1When updating a belongsTo relationship, you may use the associate method. This
2method will set the foreign key on the child model:
3
4 $account = App\Account::find(10);
5 $user->account()->associate($account);
6 $user->save();
7
8When removing a belongsTo relationship, you may use the dissociate method. This
9method will set the relationship foreign key to null:
10
11 $user->account()->dissociate();
12 $user->save();
1//id for single
2$user->reasons->attach($reasonId);
3
4//array for multiple
5$user->reasons->attach($reasonIds);
6
7$user->save();
1<?php
2
3namespace App\Models;
4
5use Illuminate\Database\Eloquent\Model;
6
7class Project extends Model
8{
9 /**
10 * Get all of the deployments for the project.
11 */
12 public function deployments()
13 {
14 return $this->hasManyThrough(Deployment::class, Environment::class);
15 }
16}