“Laravel Hasonethrough” Réponses codées

Associé Laravel

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

	$account = App\Account::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();
Lokesh003Coding

Laravel Hasonethrough

class Mechanic extends Model
{
    /**
     * Get the car's owner.
     */
    public function carOwner()
    {
        return $this->hasOneThrough(
            Owner::class,
            Car::class,
            'mechanic_id', // Foreign key on the cars table...
            'car_id', // Foreign key on the owners table...
            'id', // Local key on the mechanics table...
            'id' // Local key on the cars table...
        );
    }
}
Sore Seal

Réponses similaires à “Laravel Hasonethrough”

Questions similaires à “Laravel Hasonethrough”

Plus de réponses similaires à “Laravel Hasonethrough” dans PHP

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code