Category : pivot

I have a pivot table in my database that combines users and loans. The table is the following. user_id loan_id amount Now I have the following code to insert data into the database $user = User::find(2); $user->loans()->create([ // Some database insertion ]); $user->loans()->attach(2, [‘amount’ => ‘500’]); And I am getting this error… IlluminateDatabaseQueryException: SQLSTATE[HY000]: General ..

Read more

So I have models: Customer SubscriptionPackage What I want is to make a relationship between them with pivot table customer_subscription_package. So when I get a customer instance, i can get his subscription_package_name that is in the subscription_package table and also to get the start_date, end_date … from the pivot table. The thing in my case ..

Read more

IlluminateDatabaseQueryException with message ‘SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘db_testmasjid.jamaah_model_kajian_model’ doesn’t exist (SQL: select kajian.*, jamaah_model_kajian_model.jamaah_model_id as pivot_jamaah_model_id, jamaah_model_kajian_model.kajian_model_id as pivot_kajian_model_id from kajian inner join jamaah_model_kajian_model on kajian.id = jamaah_model_kajian_model.kajian_model_id where jamaah_model_kajian_model.jamaah_model_id = 4)’ Sourc..

Read more

i have a pivot table that i want to record some data along with user on form submit. but im getting an error illegal offset type. $user has a value. same value if i add manually it works. my controller public function store(User $user) { //dd(Request()->all()); $data = request()->validate([ ‘title’ => ‘required’, ‘link’ => ‘required’, ..

Read more

Trying this for hours now and I don’t see the error. I have a model ‘User’ and a model ‘Round’. I want to define a n:m-relation with a model ‘Flight’ as pivot model. User.php <?php namespace AppModels; use IlluminateContractsAuthMustVerifyEmail; use IlluminateFoundationAuthUser as Authenticatable; use IlluminateNotificationsNotifiable; use SpatieMediaLibraryHasMedia; use SpatieMediaLibraryInteractsWithMedia; use SpatieImageManipulations; use SpatieMediaLibraryMediaCollectionsModelsMedia; class User ..

Read more

Trying this for hours now and I don’t see the error. I have a model ‘User’ and a model ‘Round’. I want to define a n:m-relation with a model ‘Flight’ as pivot model. User.php <?php namespace AppModels; use IlluminateContractsAuthMustVerifyEmail; use IlluminateFoundationAuthUser as Authenticatable; use IlluminateNotificationsNotifiable; use SpatieMediaLibraryHasMedia; use SpatieMediaLibraryInteractsWithMedia; use SpatieImageManipulations; use SpatieMediaLibraryMediaCollectionsModelsMedia; class User ..

Read more

I am new to laravel and trying the following: I have these tables: disciplines: id | name specialties: id | name categories: id | name discipline_specialty (pivot table): id | discipline_id | specialties_id Discipline model: public function specialties() { return $this->belongsToMany(Specialty::class); } Specialty model: public function disciplines() { return $this->belongsToMany(Discipline::class); } My question is: how ..

Read more

I got 3 tables. Table 1 & 2 has their ids as foreign keys in third one(pivot). Relations for first one is $this->hasMany("AppPivot","game_id"); , second is $this->belongsToMany("AppPivot","army_id"); and pivot has relationships with both of them i.e belongsTo. My schema: I tried accessing it in controller of first one like this: $games= Game::with("armies")->get(); Result that i ..

Read more

I would like to use a ‘userables’ table to store user relationship to various other models, such as ‘Projects’ and ‘Actions’. The user relationship also has an attribute, such as "Owner" or "Contributor". I’m having trouble syncing (and/or attaching and detaching) the relationships with this additional attribute, despite trying various similar posts and scrutinising the ..

Read more

I’m creating a pivot tables for 3 columns my pivot table name is : category_post_pad category_id| post_id | pad_id ———–|———-|——– 1 | 1 | 3 1 | 4 | 1 2 | 2 | 1 Each post sent by the user includes a category and an pad Post Model public function categories() { return $this->belongsToMany(Category::class,’category_post_pad’,’post_id’,’category_id’); ..

Read more