1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

laravel associate

Last updated at Posted at 2017-08-17
//関連づけ:associate:外部キーのデータを更新する時:
$project->department()->associate(Department::find($request['department_id']));

//belongsToリレーションを削除する場合はdissociateメソッドを使用します。このメソッドはリレーションの子モデルの外部キーをnullにします。
$user->account()->dissociate();
$user->save();


//contentのserversカラスに attach:中間テープルを作成し、content_id , servers_idを入れる。多対多の時必須。
$content->servers()->attach($serverIds);

//detach:外部キーを消す、外部キーを消さないと、そのままデータを消すとエラーが出る。
$project->servers()->detach();

参考:https://readouble.com/laravel/5.4/ja/mail.html
view変数名を変える方法:with()

  public function build()
    {
        return $this->view('emails.orders.shipped')
                    ->with([
                        'orderName' => $this->order->name,
                        'orderPrice' => $this->order->price,
                    ]);
    }


//viewで使う時:
<div>
    Price: {{ $orderPrice }}
</div>
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?