Answer the question
In order to leave comments, you need to log in
Why does belongsTo work selectively in laravel?
There are two tables numbers and street, from the numbers model it belongsTo to street, but when fetching from the database, the expected data is not returned to some id, just emptiness. The fields in street are filled in identically.
$numbers = numbers::with(['street'])->where('id', '=', 5)->orderBy('created_at', 'desc')->get(); // результат 0 ?????
$numbers = numbers::with(['street'])->where('id', '=', 4)->orderBy('created_at', 'desc')->get(); // работает как надо
Answer the question
In order to leave comments, you need to log in
it seemed to me that you want to choose a nabers for the street. if so, then the queries are generally incorrect (to the wrong table
)
$street = street::find(5);
if ($street) {
$numbers = $street->numbers()->orderBy('created_at', 'desc')->get();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question