mardi 7 février 2017

Updating Pivot table by searching type on additional field - Laravel

I have 3 tables Users, Languages and Language_User as shown below:

Users

id

name

...

Languages

id

language

Language_User

id

user_id

language_id

type('learn','native')

I would like to update language_id for both the type but depending on the type.

So, if $user = User::find($id); and type is native enter language_id as 3(let's say)

similarly, if type is learn enter language_id as 4(let's say) which comes from the form of type PATCH.

I dont get it how to use this and add extra check for type: $lang = User::find($id)->languages()->updateExistingPivot($languageId, $attributes);

OR

App\User::find(1)->languages()->save($language, ['language_id' => $learn]);

How to check for type in pivot table before overriding the data.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2kLfvOH
via IFTTT

Aucun commentaire:

Enregistrer un commentaire