Answers for "laravel wherehasmorph all related models"

PHP
2

associate laravel

When updating a belongsTo relationship, you may use the associate method. This 
method will set the foreign key on the child model:

	$account = AppAccount::find(10);
	$user->account()->associate($account);
	$user->save();

When removing a belongsTo relationship, you may use the dissociate method. This
method will set the relationship foreign key to null:

	$user->account()->dissociate();
	$user->save();
Posted by: Guest on December-07-2020
0

morph relation laravel

You may register the morphMap in the boot function of your 
AppProvidersAppServiceProvider class or create a separate service provider 
if you wish.

use IlluminateDatabaseEloquentRelationsRelation;

Relation::morphMap([
    'post' => 'AppModelsPost',
    'video' => 'AppModelsVideo',
]);
Posted by: Guest on January-06-2021

Browse Popular Code Answers by Language