I have 3 table.
- Quotation (relation with Order)
- Order (relation with Quotation & Project)
- Project (relation with Order, but have no relation with Quotation)
My Model is like
Quotation Model
class Quotation extends BaseModel implements Notifiable
{ public function orders()
{
return $this->hasMany(Order::class, 'quotation_id');
}
}
Order Model
class Order extends BaseModel implements Notifiable
{
public function quotation()
{
return $this->belongsTo(Quotation::class, 'quotation_id');
}
public function project()
{
return $this->belongsTo(Project::class, 'project_id');
}
}
Project Model
class Project extends BaseModel
{
public function order()
{
return $this->hasOne(Order::class, 'project_id');
}
}
I want when i create project, its filled to project_id for every order table in same quotation (with eloquent). is that possible?
My current controller like this
public function store(ProjectRequest $request, Order $order, $number = null)
{
if (!$number) {
$number = numbering(new Project(), 'PRJ');
}
$project = Project::create($request->data($number));
$order->project()->associate($project)->save();
return \response([
'path' => "/projects/$project->id"
]);
}
But it just filled project_id just in one order row.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire