繁体   English   中英

在laravel 5.4的同一行中获取给定值的不同id的值

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM