从 table blade.php 获取 ID 到其他 blade.php 错误 Symfony\Component\Routing\Exception\RouteNotFoundException

Getting ID from the table blade.php to other blade.php error Symfony\Component\Routing\Exception\RouteNotFoundException

我有一个 table 视图,其中有一个视图按钮并重定向到另一个页面,其中包含已单击的行的 ID。

<tbody>
  <tr>
   <?php $hold=0; ?>
   @if(!empty($users))
    @foreach($users as $user)
      @if($user->role == 3)
       <?php $hold++; ?>
        <td class="py-1">{{ $user->id }}</td>
        <td>{{ $user->name }} </td>
        <td>{{ $user->Zone }} </td>
        <td>{{ $user->Purok }}</td>
        <td> Wala pa sa database </td>
        <td>
          <div class="template-demo">
            <button type="button" onclick="location.href=' {{ route ('SupAd.View_PL_Accnt/'.$user->id) }}'"  class="btn btn-outline-info btn-icon-text">
             <i class="ti-search btn-icon-append"></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

我在 web.php 路线

上有我的代码
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}'); });

我得到了错误:

Symfony\Component\Routing\Exception\RouteNotFoundException Route [SupAd.View_PL_Accnt/3] not defined.

您将路由参数放置在错误的位置。试试这个:

Route::get('View_PL_Accnt/{id}', [SupAdController::class, 'View_PL_Accnt'])->name('SupAd.View_PL_Accnt'); });

该名称用于使用 route 助手调用路由。您可以将 url 参数提供给数组中的路由助手。在你的 blade 文件中使用:

{{ route ('SupAd.View_PL_Accnt', [$user->id]) }}

你可以像

那样改变路线
Route::get('View_PL_Accnt/{id}', [SupAdController::class, 'View_PL_Accnt'])->name('SupAd.View_PL_Accnt'); });

并在点击事件上更改按钮

<button type="button" onclick="location.href='{!! route('SupAd.View_PL_Accnt', [$user->id]) !!}'"  class="btn btn-outline-info btn-icon-text">
             <i class="ti-search btn-icon-append"></i>View
              </button>