Bak Bak - 1 year ago 82
PHP Question

Destroy Multiple Records With Model Binding Laravel 5.1

I have this problem to destroy multiple recors with model binding,
I have in RouteServiceProvider.php

public function boot(Router $router)

The Destroy Method is: (I'm returning $id just to check):

public function destroy($id)
return $id;

My Url is sending

<form id="delete_offices" accept-charset="UTF-8" action="http://localhost/public/offices/18,19" method="POST"><input type="hidden" value="DELETE" name="_method">
<input type="hidden" value="CXnq068rEYlu88gemilBZKh6f4ZL5p7cELmZoe4B" name="_token">
<button type="submit" id="btn_delete" class="btn btn-danger">Delete</button>

But when I see what is returning in my controller, only return one object:

{"id":18,"name":"Main",,"phone":"9784773366","email":"","schedule":"Monday-friday: 8am-6pm","country_id":147,"state_id":476,"city_id":1178,"created_at":"2016-05-08 17:22:04","updated_at":"2016-05-08 17:24:57"}

What can I do to have the object with all info?, if I send ids 18 and 19 , I should get the 2 offices, the office info with id 18 and the info with id 19. If I send id 23 I should get only the info of the office with id=23.


Answer Source

to override any Route from Route::resource you should add this to your resource

Route::resource('office', 'OfficeController',
                ['except' => 'destroy']);

and then just add the route manualy