Tom1410
Tom1410

Reputation: 377

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()

Upvotes: 19

Views: 25790

Answers (1)

jedrzej.kurylo
jedrzej.kurylo

Reputation: 40899

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./

Upvotes: 40

Related Questions