M
M
miniven2016-04-06 11:51:46
HTML
miniven, 2016-04-06 11:51:46

How does Request work in Laravel?

I'm trying to upload an image to the server. Controller:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Models\MainScreenModel;

public function adminStore(Request $request) {
        
        // Main Screen //

        $main_screen = MainScreenModel::find(1);
        $main_screen->main_title = $request->main_title;
        $main_screen->main_subtitle = $request->main_subtitle;
        $main_screen->save();

        if (Request::hasFile('main_image')) {
            dd('Has File!!');
        };
}

Without the last if everything works fine, but with it it throws an error:
Non-static method Illuminate\Http\Request::hasFile() should not be called statically, assuming $this from incompatible context

Tried to write use Request instead of use Illuminate\Http\Request;
Then this error comes up:
Undefined property: Illuminate\Support\Facades\Request::$main_title

What is the way out of this situation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
IceJOKER, 2016-04-06
@IceJOKER

should not be called statically - doesn't that mean anything to you?
https://laravel.com/docs/master/requests#files - what about documentation?

S
Stanislav Pochepko, 2016-04-06
@DJZT

Why are you using a facade if you have already passed the request object to the controller with a line
Try
$request->hasFile()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question