T
T
Tarasovych2017-04-17 01:20:00
Laravel
Tarasovych, 2017-04-17 01:20:00

How to save the file correctly?

Controller:

public function store(Request $request)
{
...
    $image_file = Request::file('image');
        if (Request::hasFile('image'))
        {
            $image_file->move('/testupload');
        }
...
}

view:
{!! Form::file('image', null, ['class' => 'form-control']) !!}

I get an error
Non-static method Illuminate\Http\Request::file() should not be called statically, assuming $this from incompatible context

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lexey Felde, 2017-04-17
@Tarasovych

So the error says that the method of the Request object is not static and must be called through an object instance:

$request->file('image');
    if ($request->hasFile('image')) {
    ...

V
Victor, 2017-04-17
@v_decadence

In fact, you can call the file method statically, but not on the Illuminate\Http\Request class, but on the Request facade class, which is available in the root namespace: Which is almost the same as the proposed solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question