Ho to filter child table selected using with clause in laravel - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Sunday, December 12, 2021

Ho to filter child table selected using with clause in laravel

I am querying Item using following:

$itemdata = Item::with('itemimagedetails')
    ->with('variation')
    ->select('item.id', 'item.cat_id', 'item.item_name', 'item.item_description', 'item.brand', 'item.manufacturer', 'item.country_origin', 'item.ingredient_type', 'item.delivery_time', 'categories.category_name', 'item.category_unit')
    ->join('categories','item.cat_id','=','categories.id')
    ->where('item.id', $request['item_id'])->get()->first();

I want to filter variations using planid fetched from user table.

$plan = User::where('id', $request['user_id'])

I have tried:

if (count($itemdata->variation) > 0) {
    $plan = User::where('id', $request['user_id'])->get();

    foreach ($itemdata->variation as $key => $tag_name) {
        if($tag_name == $plan['plan_id']) {
            unset($itemdata->variation[$key]);
        }
    }
}

But then I get an error in the API calls.

Can someone please suggest best approach?



source https://stackoverflow.com/questions/70315250/ho-to-filter-child-table-selected-using-with-clause-in-laravel

No comments:

Post a Comment