Skip to content
Advertisement

Tag: pivot-table

Laravel paginate pivot tables

I have collections which contains custom products I need to paginate those collections products but I receive error. data With this query I can get my collection and it’s products but I’m not able to paginate products. $collection = Collection::where(‘slug’, $slug)->where(‘status’, ‘active’)->with(‘products’)->first(); With this query I receive error $collection = Product::with(‘collections’)->whereHas(‘collections’, function($query) use($slug) { $query->where(‘slug’, $slug)->where(‘status’, ‘active’)->first(); }); Error Code

Laravel: find if a pivot table record exists

I have two models which are joined by a pivot table, User and Task. I have a user_id and a task_id. What is the neatest way to check whether a record exists for this combination of user and task? Answer You have a couple options depending on your situation. If you already have a User instance and you want to

Advertisement