简体   繁体   中英

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.

        $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. try this code. does this help.

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

Why do you use class Schedule ? I think you should use class Movies to make query.

$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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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