Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Request::input Call to undefined method

I'm new to Laravel framework and now facing with a problem while trying update logged users info.

Route:

Route::post('/user/{id}', function (Request $request, $id) {
    return App\Http\Controllers\UsersController::update($request, $id);
});

public static function update($request, $id)
{
    $user = User::find($id);
    $user->name = $request->input('name');
    ...
    $user->save();
    ...
}

Error:

FatalErrorException in UsersController.php line 24: Call to undefined method Illuminate\Support\Facades\Request::input()

like image 440
Tom1410 Avatar asked Jan 13 '16 18:01

Tom1410


1 Answers

Add the following import at the top of your file:

use Illuminate\Http\Request;

otherwise your controller gets injected instance of Request class from global namespace that is an alias of Illuminate\Support\Facades\Request./

like image 96
jedrzej.kurylo Avatar answered Oct 13 '22 10:10

jedrzej.kurylo