I have not tested it, but it should work.
$zoneId = "1" //lets consider
$forZoneA = [1,2,3,4]; //these are the restaurant IDs
$restaurants = Restaurant::whereIn('id', $forZoneA)->with('items', 'orders', 'restaurant_earnings', 'restaurant_payouts')->get();
foreach($restaurants as $restaurant) {
$restaurant->zone_id = $zoneId;
$restaurantItemIds = [];
//restaurant items
foreach ($restaurant->items as $restaurantItem) {
array_push($restaurantItemIds, $restaurantItem->id);
}
$restaurantOrderIds = [];
//restaurant orders
foreach ($restaurant->orders as $restaurantOrder) {
array_push($restaurantOrderIds, $restaurantOrder->id);
}
$restaurantEarningsIds = [];
//restaurant earnings
foreach ($restaurant->restaurant_earnings as $restaurantEarning) {
array_push($restaurantEarningsIds, $restaurantEarning->id);
}
$restaurantPayoutsIds = [];
//restaurant payouts
foreach ($restaurant->restaurant_payouts as $restaurantPayout) {
array_push($restaurantPayoutsIds, $restaurantPayout->id);
}
DB::table('items')->whereIn('id', $restaurantItemIds)->update(['zone_id' => $zoneId]);
DB::table('orders')->whereIn('id', $restaurantOrderIds)->update(['zone_id' => $zoneId]);
DB::table('restaurant_earnings')->whereIn('id', $restaurantEarningsIds)->update(['zone_id' => $zoneId]);
DB::table('restaurant_payouts')->whereIn('id', $restaurantPayoutsIds)->update(['zone_id' => $zoneId]);
$restaurant->save();
}
dd("DONE");
With the above code, the restaurants with ID of 1, 2, 3, 4 will be added to the zone with ID: 1
You can paste the above code inside dashboard() function of AdminController.php and go to the dashboard page once to execute it. If all is successful, you will get a "DONE" message.
Screenshot where you can paste the code:
Then again change the code and run again with your appropriate changes (changes of restaurant ids and zone ids)