Issue
I don't know where this error came from it says. I got this error when I tried to update my records. It works properly and updating into my database but getting this error. It says that that missed something in my parameter. I think my error is return redirect()->route('account.show');
when I tried to redirect to my show view after updating. But when I redirect to other works fine. Any opinions?
Missing required parameters for [Route: account.show] [URI: show/{id}].
I have 3 blade template. search, edit and show.
search.blade.php - To show all the records.
@foreach ($result as $row)
<tr class = "success">
<td>{{ $row->id }}</td>
<td>{{ $row->first_name }}</td>
<td>{{ $row->last_name }}</td>
<td>{{ $row->middle_name }}</td>
<td>{{ $row->email }}</td>
<td>{{ $row->username }}</td>
<td>
<a href = "{{ route ('account.show', $row->id) }}"><button type = "submit" class = "btn btn-info">View</button></a>
<a href = "{{ route ('account.edit', $row->id) }}"><button type = "submit" class = "btn btn-warning">Edit</button></a>
<a href = "{{ route ('result.destroyEmployee', $row->id) }}"><button type = "submit" class = "btn btn-danger">Archive</button></a>
</td>
</tr>
@endforeach
edit.blade.php - Here where I got the error after hitting the submit button which is Save
<div class = "col-md-6">
<form class = "form-vertical" role = "form" method = "post" action = "{{ route ('account.edit', $result->id) }}">
<h3>Edit Employee</h3>
<hr>
<div class = "form-group">
<label for = "email" class = "control-label">Email Address</label>
<input type = "text" name = "email" class = "form-control" value = "{{ $result->email }}">
</div>
<div class = "form-group">
<label for = "username" class = "control-label">Username</label>
<input type = "text" name = "username" class = "form-control" value = "{{ $result->username }}">
</div>
<div class = "form-group">
<button type = "submit" class = "btn btn-success">Save</button>
</div>
<input type = "hidden" name = "_token" value = "{{ Session::token() }}">
</form>
show.blade.php - Textfield's will just place the value of the records.
<div class = "col-md-6">
<form class = "form-vertical" role = "form" method = "post" action = "{{ route ('account.show', $result->id) }}">
<h3>View Employee</h3>
<hr>
<div class = "form-group">
<label for = "email" class = "control-label">Email Address</label>
<input type = "text" name = "email" class = "form-control" placeholder = "{{ $result->email }}" readonly>
</div>
<div class = "form-group">
<label for = "username" class = "control-label">Username</label>
<input type = "text" name = "username" class = "form-control" placeholder = "{{ $result->username }}" readonly>
</div>
<input type = "hidden" name = "_token" value = "{{ Session::token() }}">
</form>
Routes:
//READ
Route::get('/search',
[
'uses' => '\App\Http\Controllers\AccountController@getEmployee',
'as' => 'account.search',
]);
//SHOW
Route::get('/show/{id}',
[
'uses' => 'AccountController@showEmployee',
'as' => 'account.show',
]);
//EDIT
Route::get('/edit/{id}',
[
'uses' => '\App\Http\Controllers\AccountController@editEmployee',
'as' => 'account.edit',
]);
//UPDATE
Route::post('/edit/{id}',
[
'uses' => '\App\Http\Controllers\AccountController@updateEmployee',
'as' => 'account.edit',
]);
Solution
Try to change this:
<form class = "form-vertical" role = "form" method = "post" action = "{{ route ('account.show', $result->id) }}">
To:
<form class = "form-vertical" role = "form" action="{{ url('edit/'. $result->id) }}" method="POST">
Then you have to pass the route parameters as second argument to route. Something like this: return redirect()->route('account.show', [$id])
*I would recommend you to use laravel collective form: https://laravelcollective.com/
With laravel collective you can do something like this:
{!! Form::open(array('route' => array('account.show', $result->id))) !!}
Answered By - Panagiotis Koursaris
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.