1
votes

I registered this resource:

Route::resource('order-item-paxes', 'OrderItemPaxController', ['except' => ['show', 'create', 'store']]);

The problem is that I cannot get the model in the controller doing this:

public function edit(OrderItemPax $order_item_pax)
{
    $order_item_pax = OrderItemPax::find($id);    
    return view('production.order-item-paxes.edit', compact('order_item_pax'));
}

$order_item_pax->toArray() returns an empty Array.

I checked the routes through php artisan route:list and its returning something strange:

PUT|PATCH | production/order-item-paxes/{order_item_paxis}

It should be order_item_pax instead of order_item_paxis.

Any idea?

UPDATE

If I use $order_item_paxis in my controller it works. I've registered hundreds of Resources and I've always used the singular version of the name

1
I actually think I know the problem with this one. In Symfony there is a class called Inflector (github.com/symfony/inflector/blob/master/Inflector.php) which has a method called 'singularize'. I believe that 'paxes' would come out as 'paxis'. E.g. Axes would become Axis. I have a firm belief that this is what is happening with your routes. - Farkie
I think you'll manually have to do: ['names' => ['update' => 'order-item-paxes']]); - Farkie

1 Answers

0
votes

You can tell Laravel to override the route parameters by including parameters array in the $options array (3rd param):

Route::resource('order-item-paxes', 'OrderItemPaxController', [
    'except' => ['show', 'create', 'store'],
    'parameters' => ['order-item-paxes' => 'order_item_pax']
]);

Hope this helps!