1 year ago

problem with find in many to many

Posted 1 year ago by haizone

i have a problem

this code dosnt work:

    $businesses = Business::where('slug', $slug)
    'reviews' => function ($query) {
        $query->select('slugi', 'name');
])->first(['id', 'name']);
return response()->json($businesses);

i get:


"id": 2852, "name": "biz name", "ReviewsCount": 17, "ReviewsAvg": "3.9", "reviews": [

] }

the reviews is empty (and i have a data inside)

but if i do like this:

$business = Business::where('slug', $slug)->first()->reviews()->get();

i get all the info

someone know what is the problem?

Please sign in or create an account to participate in this conversation.