I am currently working on a 1 page crud for a laravel project. I had a lot of trouble to begin with, but now the last error i have is
Too few arguments to function 0 passed and 1 expected
this happens on loading the main page of the crud. this file gives the error: edit.blade.php
<form method="post" action="{{ route('admin.user.update', $userEdit->id) }}">
@method('PATCH')
@csrf
<div >
<label for="name"> Name:</label>
<input type="text" name="name" value="{{ $userEdit->name }}" />
</div>
<div >
<label for="email">email </label>
<input type="email" name="email" value="{{ $userEdit->email }}" />
</div>
<button type="submit" >Update</button>
</form>
controller index:
public function index($id)
{
$users = User::all();
$userEdit = User::find($id);
return view('admin.user.index', compact('users', 'userEdit'));
}
yes i need $users and $userEdit, but i cant reach $userEdit on the first load of the page. normally there is also no $id in index() but i added it to try to fix it, this did not work
CodePudding user response:
You need to pass the parameter in as an array with a key specifying the route's parameter name. See https://laravel.com/docs/9.x/routing#generating-urls-to-named-routes
<form method="post" action="{{ route('admin.user.update', ['id' => $userEdit->id]) }}">
CodePudding user response:
you have a error in your form:
<form method="post" action="{{ route('admin.user.update', $userEdit->id) }}">
@csrf
@method('PUT')
<div >
<label for="name"> Name:</label>
<input type="text" name="name" value="{{ $userEdit->name }}" />
</div>
<div >
<label for="email">email </label>
<input type="email" name="email" value="{{ $userEdit->email }}" />
</div>
<button type="submit" >Update</button>
</form>
method not it´s PATCH
it´s PUT
and firts send your CSRF