Currently I have this mysql query in my php code. I want to optimize it better because this query is currently inside a while loop and this query alone takes 25 seconds. so the bigger the loop the time it takes to execute this query over and over starts to become insane in only a short time. So I would
Tag: pivot-table
Laravel Sync username into pivot table
I have an extra column for usernames in my role_user pivot table, how can I sync the username with the roles ? role_user pivot table I need to sync the user name in the name field This is the update …
Userpermission pivot-function is only accessible via the Auth class
I have a simple Userpermission System consisting of 3 tables: users, permissions and the pivot table permission_user. This is the User model: and here is the Permission Model: Now when I try to get all the permissions of the currently logged in user with this: it works without problems. But when I try to get another Users Permissions like this:
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