Reputation: 1216
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??
Upvotes: 1
Views: 157
Reputation: 1238
you can get id like it. try this code. does this help.
$movieIds = Schedule::where('movtitle', '=', $request->Cinename)->get(['movie_id']);
Upvotes: 3
Reputation: 2852
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
}
Upvotes: 2