1.一次插入多個值

DB::table('item_statuses')->insert([['event'=>'payed'],['event'=>'recieved'],['event'=>'sended'],['event'=>'arrived']]);
2.attach時帶timestamps
public function favorites()
{
    return $this->belongsToMany(User::class, 'favorites')->withTimestamps(); 
}

2.

要讓pivot的資料按照order by

item_details是樞紐表名稱

public function itemStatus(){
return $this->belongsToMany(ItemStatus::class,'item_details','item_id','item_statuses_id')->withTimestamps()->orderBy('item_details.created_at','desc');
}

 

 

arrow
arrow
    全站熱搜

    學習程式 發表在 痞客邦 留言(0) 人氣()