php - Can't retrieve records using foreign key on the same table in Laravel 5.2 -
i'm using laravel 5.2 retrieve records database.
my table (simplified):
services: id name parent_id parent_id fk same table (fk services.id).
this code returns empty collection:
$category->services->where( 'parent_id', 0 ) select other condition works properly. ex.
$category->services->where( 'name', 'foo ) returns not empty results.
raw sql works fine too:
select * services parent_id = 0; what wrong eloquent or how use in way can retrieve records concrete parent_id ?
your query should this:
$services = $category->services()->where('parent_id', 0)->get()
Comments
Post a Comment