2017-07-17 44 views
1

我有一个文本输入,用户必须输入电影的名字,我也有一个电影数据库,当用户输入电影的标题,电影的标题将与电影数据库上的标题相匹配,然后应该在电影表中获取电影的movie_id并将其保存在电视节目表中。从laravel 5.4的同一行得到一个不同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?? 
+1

如何阅读Laravel的基本文档? –

+1

同意@RoboRobok 看起来你使用的是Eloquent:https://laravel.com/docs/5.4/eloquent –

回答

3

你可以得到喜欢它的id。试试这个代码。这有助于吗?

$movieIds = Schedule::where('movtitle', '=', $request->Cinename)->get(['movie_id']); 
2

为什么使用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 
} 
相关问题