我有三个表:user,request和request_user我想在数据透视表中插入user_id和req_id。请帮忙
//code for user.php.
public function ssrareqs()
{
return $this->belongsToMany(Ssrareq::class, 'request_user');
}
request.php
protected $fillable = ['particular_id','quantity_req', 'quantity_issued', 'status_issue', 'status_req', 'purpose', 'remarks', 'date_applied',
'date_approved', 'date_issued', 'approver', 'issuer'];
public function users()
{
return $this->belongsToMany(User::class, 'ssrareq_user');
}
protected $primaryKey = 'req_id';
myController的
public function store(Request $request)
{
$storereq = new Ssrareq([
'particular_id' => $request->get('particular_id'),
'quantity_req' => $request->get('quantity_req'),
'purpose' => $request->get('purpose'),
'date_applied' => \Carbon\Carbon::now()->format('Y-m-d'),
]);
$storereq->save();
$storereq->users()->sync($request);
return redirect('/requester');
}