对不起,我无法将两个id从URL传递给控制器,这给我一个错误未定义变量:id
控制器中用户ID的问题
我的路线:
Route::get('addappotouser/{id}/{dates_id}','UsersController@create');
Href:
<a href="{{url('addappotouser' . '/'. $usersss->id .'/'. $date->id)}}" value="" class="btn btn-success btn-mini deleteRecord" type="submit">{{$date->Dates}}</a>
控制器:
public function create( $id , $dates_id)
{
$bookappoitm=DB::table('times')
->where('times.Dates_id',$dates_id)
// ->where('times.Dates_id',1)
->whereNoTIn('times.id',function($query){
$query->select('times_id')->from('bookappoitments')
->where('users_id',$id)
->get();
})
->get();
$datee=Dates::find($dates_id)
->where('dates.id',$dates_id)
->select('dates.*')
->first();
$userss=User::find($id)
->where('id',$id)
->select('users.*')
->first();
return view('admin.Managers.addappotouser', compact('bookappoitm','datee','userss'));
URL:
http://127.0.0.1:8000/addappotouser/1/1
答案 0 :(得分:0)
您需要将参数作为数组传递,请参见https://laravel.com/docs/5.6/helpers#method-route,
IFERROR(1/(1/ ComplexFunction() ))
答案 1 :(得分:0)
按如下所示更改行:
->whereNoTIn('times.id',function($query) use ($id){
答案 2 :(得分:0)
以此更新代码,您需要像这样使用$id
$bookappoitm=DB::table('times')->where('times.Dates_id',$dates_id)->whereNoTIn('times.id',function($query) use ($id){
$query->select('times_id')->from('bookappoitments')
->where('users_id',$id)
->get();
})
->get();