[英]Get the value of a different id given a value from the same row in laravel 5.4
我有一個文本輸入,用戶必須輸入電影的名稱,還有一個電影數據庫,在該數據庫中,當用戶鍵入電影的標題時,電影的標題將與電影數據庫上的標題匹配,然后應該在電影表中獲取電影的movie_id,並將其保存在時間表表中。
$movtitle = $request->Cinename;
$mov_tit = Schedule::where('movtitle', '=', $movie->title);
$mov_id = find($movie->movie_id where $title = $mov_tit);
//this is wrong. what is the correct syntax??
你可以得到喜歡的ID。 試試這個代碼。 這樣做有幫助。
$movieIds = Schedule::where('movtitle', '=', $request->Cinename)->get(['movie_id']);
為什么使用班級Schedule
? 我認為您應該使用Movies
類進行查詢。
$movtitle = $request->Cinename;
//use Movies model to get the list of movies
$movies = Movies::where('movtitle', '=', $movtitle)->get();
foreach($movies as $movie){
// do something with each object $movie
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.