在vue js中缺少Route的必需参数

时间:2017-12-22 09:19:40

标签: laravel

我只想调用只有一个用户ID的数据: 我得到以下错误:

缺少[Route:VLead] [URI:VLead / {id}]的必需参数。 (查看:C:\ wamp64 \ www \ S2 \ resources \ views \ admin \ sidebar \ sidebar.blade.php)(查看:C:\ wamp64 \ www \ S2 \ resources \ views \ admin \ sidebar \ sidebar.blade。 PHP)

Route::get('/VLead/{id}', 'ClientController@index_lead')->name('VLead')->middleware('user'); 控制器

public function index_lead($id)
   {
     $clients = DB::table('clients')->where('Stage','<>',"Active" )
                                    ->orderBy('id', 'Aesc')
                                    ->get();
      return view('admin.VLead',compact('clients'));
   }
<script language="javascript" type="text/javascript">
          var scrt_var = {{ Sentinel::getuser()->id}}; 
</script>

<li><a class="" href="{{route('VLead')}} "onclick="location.href=this.href+'/'+scrt_var;return false;" >Leads</a></li>

2 个答案:

答案 0 :(得分:1)

您需要将{{route('VLead')}}更改为{{route('VLead', Sentinel::getuser()->id)}}或通过将id更改为Route::get('/VLead/{id}'

Route::get('/VLead/{id?}'参数设为可选

答案 1 :(得分:0)

您收到错误是因为未传递必需参数。做这样的事情:

{{ route('VLead', ['id' => $userId]) }}