简体   繁体   English

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

[英]Get the value of a different id given a value from the same row in laravel 5.4

I have a text input where the user has to type the name of the movie and I also have a movie database in which when the user typed the title of the movie, the title of the movie will match the title on the movies database then it should get the movie_id of the movie in movies table and save it on the schedules table. 我有一个文本输入,用户必须输入电影的名称,还有一个电影数据库,在该数据库中,当用户键入电影的标题时,电影的标题将与电影数据库上的标题匹配,然后应该在电影表中获取电影的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??

you can get id like it. 你可以得到喜欢的ID。 try this code. 试试这个代码。 does this help. 这样做有帮助。

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

Why do you use class Schedule ? 为什么使用班级Schedule I think you should use class Movies to make query. 我认为您应该使用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