-1

I have three tables namely clients, orders & websites. The website has a belongsTo field which belongs to a client_id from "clients" table. I may need to change the client_id for a website which works fine with laravel Nova. In mycase I also need to change the client_id automatically for the particular website_id in the orders table whenever I change the client_id of a website.

In brief, whenever I change the owner of the website, all the orders made for the website in "orders" table need to be updated to the new owner. I can do it with laravel, but with Nova I am lost.

Francisco
  • 10,918
  • 6
  • 34
  • 45

1 Answers1

0

It can be solved using Eloquent’s event. In this Case: while updating the websites table, Create an event for update. This event will be called when a website is updated. Use update query to resolve these changes by updating the clientID for the particular Website in the Orders table.

static::updated(function ($website) {

   $ClientID = $website->client_id;

   $WebsiteID = $website->id;

   Order::where('website_id', $WebsiteID)
           ->update(['client_id' => $ClientID]);

});

Or else this can be solved by creating an Observer for website table and implement the same process using the updated function.