I have a table view in which I have a view button and redirect to another page carrying the id of the row that has been clicked.
<tbody>
<tr>
<?php $hold=0; ?>
@if(!empty($users))
@foreach($users as $user)
@if($user->role == 3)
<?php $hold ; ?>
<td >{{ $user->id }}</td>
<td>{{ $user->name }} </td>
<td>{{ $user->Zone }} </td>
<td>{{ $user->Purok }}</td>
<td> Wala pa sa database </td>
<td>
<div >
<button type="button" onclick="location.href=' {{ route ('SupAd.View_PL_Accnt/'.$user->id) }}'" >
<i ></i>View
</button>
</div>
</td>
</tr>
@endif
@endforeach
<?php if($hold == 0){
echo "<p><font color=red size='4pt'>No purok leader can be found</font></p>";
}
?>
@endif
I have here my code on web.php route
Route::group(['prefix'=>'SupAd_Purok_Leader_Account', 'middleware'=>['isSupAd', 'auth', 'PreventBackHistory']], function (){
Route::get('View_PL_Accnt', [SupAdController::class, 'View_PL_Accnt'])->name('SupAd.View_PL_Accnt/{id}'); });
And I got the error:
Symfony\Component\Routing\Exception\RouteNotFoundException Route [SupAd.View_PL_Accnt/3] not defined.
CodePudding user response:
You are placing the route parameter in the wrong place. Try this:
Route::get('View_PL_Accnt/{id}', [SupAdController::class, 'View_PL_Accnt'])->name('SupAd.View_PL_Accnt'); });
The name is used to call a route using the route
helper. You can give the url parameters to the route helper in an array. Inside your blade file use:
{{ route ('SupAd.View_PL_Accnt', [$user->id]) }}
CodePudding user response:
you can change routes like
Route::get('View_PL_Accnt/{id}', [SupAdController::class, 'View_PL_Accnt'])->name('SupAd.View_PL_Accnt'); });
And change the button on click event
<button type="button" onclick="location.href='{!! route('SupAd.View_PL_Accnt', [$user->id]) !!}'" >
<i ></i>View
</button>