我已經將刀片文件中的控制器值作爲{{ $user->user_name }}
獲取。我想在相同的刀片文件中傳遞值以查詢。將刀片文件中的控制器獲取值傳遞給查詢
sample.blade.php
{{$user->user_name}}
$test=db::table('department')->where('department.parent_department','=','{{ $user->user_name }}')->get();
我已經將刀片文件中的控制器值作爲{{ $user->user_name }}
獲取。我想在相同的刀片文件中傳遞值以查詢。將刀片文件中的控制器獲取值傳遞給查詢
sample.blade.php
{{$user->user_name}}
$test=db::table('department')->where('department.parent_department','=','{{ $user->user_name }}')->get();
你可以像這樣使用它,不需要花括號。
$test=DB::table('department')->where('department.parent_department','=',$user->user_name)->get();
只是刪除{{ }}
周圍的變量
$test = DB::table('department')
->where('department.parent_department','=', $user->user_name)
->get();
當然
,意見不寫你的查詢的好地方。相反,嘗試把它放在控制器
刪除這些{{}}沒必要「department.parent_department''parent_department」的,將工作過
$test = DB::table('department')
->where('parent_department','=', $user->user_name)
->get();
希望這樣只會一件事幫你在視圖{{}}中使用
並且不需要'='。 – Utwo
我知道,但它也會工作 –
視圖不適合查詢。說,你應該刪除braquet,因爲你在php塊 – okante