How can I select certain fields using with()

Posted 5 months ago by lararocks

How can I select certain fields using with().

My current query is:

$categories = Category::where('parent_id', 0)->with('children')->select('id', 'name')->get();

Currently children categories return all fields while I want children categories to only return id and name similar to parent/main categories.

Thanks

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