php - laravel trying to pluck received id, can't use it
Get the solution ↓↓↓What i want to achieve is getting few movie_id's from the MovieRating. and then find these id's in Movie. But i receive an errorSQLSTATE[HY000]: General error: 25 column index out of range (SQL: select * from "movies" where "id" = 1)
public function index(){
$movies = Movie::orderByDesc('id')->paginate(5);
// <problem>
$bestMoviesRatings = MovieRating::orderByDesc('average')->with('movie')->pluck('movie_id');
$bestRatedMovies = Movie::where('id', $bestMoviesRatings)->get();
// </problem>
return view('movies/mainMovies', compact('movies', 'bestRatedMovies'));
}
Does anybody know how to help me? thanks 4 help
Answer
Solution:
Try this one because your variable $bestMoviesRatings is an array I think.
$bestRatedMovies = Movie::whereIn('id', $bestMoviesRatings)->get();
Answer
Solution:
Hey I'm not 100% about your database stracture but I think should try whereIn insted of where
$bestRatedMovies = Movie::whereIn('id', $bestMoviesRatings)->get();
Thanks!
Answer
Solution:
You can try
$bestMoviesRatings = MovieRating::orderByDesc('average')->pluck('movie_id')->all();
$bestRatedMovies = Movie::whereIn('id', $bestMoviesRatings)->get();
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: php_network_getaddresses: getaddrinfo failed: temporary failure in name resolution
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.