#### Category : many-to-many

I am not very proficient in programming so I would ask for your help. I want to connect the user and tasks table to in my database and assign tasks to different users. Tasks are uploaded successfully but my user_task table is empty after i upload a task. I would like to use many to ..

I want a system where I connect users with tasks and later I can assign tasks to different users from the amdin panel. My program doesn’t work, it doesn’t assign tasks to users. Later, I want to make sure that when a user logs in, they can only see their own tasks that an amdin ..

I must be going insane or be really tired. So I have this situation where I get a collection of all the Roles assigned to the User. That part goes ok…. however I noticed something super strange. I am using Laravel 8 and PHP8 (not the strange part). For some reason, I do not get ..

I need some help to delete a movie from my database. I know that since I have pivot tables I will get some troubles with foreign key(my delete controller gives this error), but I don’t know how to solve it. The error i’m getting is the following: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or ..

I have two models, Menu and User with many to many relationship. So, at this moment I have lot of records with the same user_id and menu_id in the pivot table, and the user must to can detach only one of them and not all of them. So, I made a AJAX request to "remove" ..

I have the following structure: Charge id amount created_at .. Payment id amount created_at .. and a pivot table charge_payment, since one charge can be covered partially by multiple payments. charge_payment charge_id payment_id amount The amount column on the pivot table defines the amount that the given Payment covers for the Charge. And I need ..

I’m fairly now to using Pivot tables, and Many to Many relations overall, so hopefully I can learn what the issue is here. I have a many to many relation between beers and beer lists, and I have a custom made pivot table: Schema::create(‘beer_list_pivot’, function (Blueprint $table) {$table->id(); $table->foreignId(‘beer_id’)->constrained();$table->foreignId(‘list_id’)->constrained(); }); And the relations ..

I’m fairly now to using Pivot tables, and Many to Many relations overall, so hopefully I can learn what the issue. I have a many to many relation between beers and beer lists, and I have a custom pivot table: Schema::create(‘beer_list_pivot’, function (Blueprint $table) {$table->id(); $table->foreignId(‘beer_id’)->constrained();$table->foreignId(‘list_id’)->constrained(); }); And the relations are looking like ..

I am in a strange situation where not getting clarity on how should I define relationship between Models. I would like to know the experts opinion on how should I approach designing the relationship. Assume I have 3 tables. Users (id, name, email, password…etc.) Tags (id, user_id, name, created_at…etc.) Contacts (id, name, email, dob, phone…etc.) ..

it should be simple, but something is wrong and Idk why. I need many-to-many replationship for the same model, theoretically I know how to do this but I’m receiving strange reasult. Maybe it is caused by non-integer index column. Pn Model: class Pn extends Model { protected $primaryKey = ‘pn’; protected$guarded = []; public ..

I have a many-to-many relationship between three tables (Courses , Professors , Hours) I created a 4th table called course_hour_professors to make the relation and I made it one-to-many relationship between the 4 tables because I know that if I get a pivot table with more than two FKs, I have to treat it as ..

Hello mine foreach loop returns a Call to a member function bookmarkItems() on int, when I try to seed mine database. I don’t understand what I am missing laravel docs poly relation I have setup the relationsships like this and then when I am trying to save the new bookmarkitem is returns the error. stack ..

Hello mine foreach loop returns a Call to a member function bookmarkItems() on int, when I try to seed mine database. I don’t understand what I am missing laravel docs poly relation I have setup the relationsships like this and then when I am trying to save the new bookmarkitem is returns the error. stack ..

I have registered successfully records in the pivot table using sync adding extra fields. I’m trying of retrieve the qualities that belongs to one buyer through php artisan tinker, However I’m getting an empty array [] or using the web app I got a null array. >>> $buyer = AppModelsBuyer::first(); => AppModelsBuyer {#4513 id: 24, .. Read more Good day. I have this stuff that has been a little bit problematic for me in my application. I have a Staff model which has a many to many relationship with a Company model. Hence, I have a company_staff table.So, the companies have a unique identifier which is the company code. The Staff model has .. Read more I am trying to get a list of products matching a vendor_id. The tables Products and Vendors have a many to many relationship, therefore I created a pivot table with the fields vendor_id and product_id. The Eloquent query below: Product::with(‘brand’,’tax’) ->has(‘vendors’) ->where(‘vendor_id’,$vendor_id) ->get(); Although not visible in the query, I have a trait BelongsToTenant that ..

I have many to many relation ship between Product and order through order_details, how i can get top 5 sale product? Product: public function orders() { return $this->belongsToMany(Order::class, ‘order_details’); } Order: public function products() { return$this->belongsToMany(Product::class, ‘order_details’)->withPivot([‘quantity’, ‘sale_price’]); } Pivot table: public function up() { Schema::create(‘order_details’, function (Blueprint $table) {$table->id(); $table->foreignId(‘order_id’);$table->foreign(‘order_id’) ->on(‘orders’) ..

I have a pivot table with fields: language_id lesson_id name folder_path index_path download_path I need to update the table with this array of data. How can I achieve that? This is my array: array:2 [ 0 => array:5 [ "language_id" => "17adbf30-9164-4a54-894c-17ad042123ae" "name" => "test" "folder_path" => "http://136.234.3.75/quest_admin" "download_path" => "http://136.234.3.75/quest_admin" "index_path" => "http://136.234.3.75/quest_admin" ] ..

I have a Many to Many relationship between Wallet & User Models: User.php: public function wallets() { return $this->belongsToMany(Wallet::class,’user_wallet’,’user_id’,’wallet_id’)->withPivot(‘balance’); } Wallet.php: public function users() { return$this->belongsToMany(User::class,’user_wallet’,’wallet_id’,’user_id’)->withPivot(‘balance’); } And the pivot table user_wallet goes like this: Now I need to get the name of wallets and the balance of that wallet in a table at ..

I have next tables in my Laravel project Posts id title 1 post1 2 post2 3 post3 4 post4 5 post5 Tags id name 1 tag1 2 tag2 3 tag3 4 tag4 5 tag5 post_tag post_id tag_id 1 1 1 2 1 3 1 5 2 2 3 2 3 3 3 5 4 2 ..

I have a Many To Many relationship between User Model & Wallet Model: Wallet.php: public function users() { return $this->belongsToMany(User::class); } And User.php: public function wallets() { return$this->belongsToMany(Wallet::class); } And I want to get wallet list of a single user like this: @forelse($user->wallets as$wallet) <tr> <td>{{ $wallet->id }}</td> </tr> @empty <td colspan="5" class="text-center">No .. Read more I have a Many To Many relationship between User Model & Wallet Model: Wallet.php: public function users() { return$this->belongsToMany(User::class); } And User.php: public function wallets() { return $this->belongsToMany(Wallet::class); } And I have these three tables related to Wallets: Table wallets: public function up() { Schema::create(‘wallets’, function (Blueprint$table) { $table->bigIncrements(‘id’);$table->string(‘title’); $table->string(‘name’)->unique();$table->tinyInteger(‘is_active’); $table->tinyInteger(‘is_cachable’); .. Read more Lets say I have a User, Roles and User_Role table. I have a custom pivot model for my User_Role table. In a User model I have a relation like this public function roles() { return$this->belongsToMany(Role::class, ‘User_Role’) ->using(UserRole::class); } I have a global scope inside UserRole model which is not included in this relation. I ..