A
A
amk2016-12-31 04:27:33
Laravel
amk, 2016-12-31 04:27:33

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

3 answer(s)
H
hakkol, 2016-12-31
@hakkol

stackoverflow.com/questions/27753868/how-to-get-th...

6
65536, 2016-12-31
@65536

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();
}

A
amk, 2016-01-01
@ifired

Thanks everyone, laravel works like clockwork. It turned out that the entry in one of the linking tables was deleted

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question