0

i have in my controller

public function details($id)
    {
        $claim = Claim::findOrFail($id);
        $details = $claim->details;

        return response()->json([], 200);
    }

and I have in my routes

Route::resource('claims', 'Admin\\ClaimsController',['names'=> ['details'=>'admin.claims.details'], 'only' => ['index','store','update','destroy','details']]);

when I run php artisan route:list i do not see the admin.claims.details( admin/claims/1/details) in the list

the documentation is pretty vague here so I'm asking how to properly set a custom route? How do I specify if its "POST" or "GET"?

Kendall
  • 5,065
  • 10
  • 45
  • 70

1 Answers1

1

To override the default resource controller actions' route names, you can pass a names array with your options.

For example:

Route::resource('claims', 'ControllerClassName', [
    'names' => [
        'index' => 'admin.claims.details',
        'create' => 'admin.claims.create',
        // etc...
    ], 
    'only' => [
        'index','store','update','destroy','details'
    ]
]);

REF: https://laravel.com/docs/5.2/controllers#restful-naming-resource-routes


Here are examples of setting custom named get/post routes.

GET Route

Route::get('claims', ['as' => 'admin.claims.details', uses => 'ControllerClassName']);

POST Route

Route::post('claims', ['as' => 'admin.claims.details', uses => 'ControllerClassName']);

REF: https://laravel.com/docs/5.2/routing#named-routes

Kabelo2ka
  • 419
  • 4
  • 14
  • Ohh! I think I misunderstood the use case for "router naming" I have a method "details" for which I want to use "/admin/claims/{id}/details" as a route to the controller method. – Kendall Nov 21 '16 at 18:02
  • 1
    You can use `Route::get('admin/claims/{id}/details', ['as' => 'admin.claims.details', uses => 'ControllerClassName@details']); ` and in your controller details method you'll have access to the `$id` variable. – Kabelo2ka Nov 21 '16 at 22:54