Category : many-to-many

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 ..

Read more

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 ..

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 ..

Read more

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’) ..

Read more

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" ] ..

Read more

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 ..

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 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 ..

Read more