Try to search your question here, if you can't find : Ask Any Question Now ?

Too few arguments to function AppHttpControllersMyControllersGameController::update(), 2 passed and exactly 3 expected

HomeCategory: stackoverflowToo few arguments to function AppHttpControllersMyControllersGameController::update(), 2 passed and exactly 3 expected
Avatargaurav asked 5 months ago

I get this error when I try to update my posts

In form everything is correct I guess, because I haven’t changed anything there.

Thats my form method:

<form method="post" action="{{ route('games.update', $game->id) }}">
@method('PATCH')
@csrf
</form>

This is my update method:

everything was working but suddenly it started giving this error

public function update(Request $request, $id, Game $game)
{
    if ($game->author !== auth()->user()->id || auth()->user()->cannot('edit games'))
        abort(404);

    $request->validate([
        'title' => 'required',
        'type' => 'required',
        'city' => 'required',
        'district' => 'required',
        'comment' => 'required',
        'full_comment' => 'required',
        'photo' => 'sometimes|mimes:jpeg,jpg,gif,bmp,png',
    ]);

    $game = Game::find($id);
    $game->title = $request->get('title');
    $game->type = $request->get('type');
    $game->city = $request->get('city');
    $game->district = $request->get('district');
    $game->comment = $request->get('comment');
    $game->full_comment = $request->get('full_comment');

    if ($request->has('photo')) {

        $photoName = $game->id . '_photo' . time() . '.' . request()->photo->getClientOriginalExtension();
        $game->photo = $request->get('photo');
        $game->photo = $photoName;
        $request->photo->storeAs('game-photos', $photoName);
    }


    $game->save();

    return redirect('/games')->with('success', 'Game has been  updated');
}
1 Answers
Best Answer
AvatarMatthias answered 5 months ago
Your Answer

15 + 12 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com