Presto's avatar

Route Resource (Edit) Not Found

Hello everyone,

I'm stumped on this one, I created a route resource in my routes file, all of the routes are working except the edit route, why? If I run php artisan route:list and the edit route is listed:

| GET|HEAD  | flyers               | flyers.index   | App\Http\Controllers\FlyerController@index |
| GET|HEAD  | flyers/create        | flyers.create  | App\Http\Controllers\FlyerController@create |
| DELETE    | flyers/{flyers}      | flyers.destroy | App\Http\Controllers\FlyerController@destroy |
| GET|HEAD  | flyers/{flyers}      | flyers.show    | App\Http\Controllers\FlyerController@show |
| PUT       | flyers/{flyers}      | flyers.update  | App\Http\Controllers\FlyerController@update |
| PATCH     | flyers/{flyers}      |                | App\Http\Controllers\FlyerController@update |
| GET|HEAD  | flyers/{flyers}/edit | flyers.edit    | App\Http\Controllers\FlyerController@edit |

My code in my routes file looks like this:

Route::resource('flyers', 'FlyerController');

Ps. this project is running Laravel v5.1

0 likes
12 replies
bashy's avatar

What do you get on the flyers/{param}/edit URI?

Presto's avatar

Sorry forgot to add that in my last post:

ErrorException in UrlGenerator.php line 306: Route [flyers] not defined. (View: /html/resources/views/flyers/edit.blade.php)

bashy's avatar

That means something in your view like this

{!! route('flyers') !!}

should be something like

{!! route('flyers.edit') !!}
// or
{!! route('flyers.index') !!}
Presto's avatar

I don't have anything like that in my view, here is the error for the log:

[2016-01-28 11:43:00] local.ERROR: exception 'InvalidArgumentException' with message 'Route [flyers] not defined.' in /html/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:306
Stack trace:
#0 /html/vendor/illuminate/html/FormBuilder.php(803): Illuminate\Routing\UrlGenerator->route('flyers', Array)
#1 /html/vendor/illuminate/html/FormBuilder.php(763): Illuminate\Html\FormBuilder->getRouteAction(Array)
#2 /html/vendor/illuminate/html/FormBuilder.php(104): Illuminate\Html\FormBuilder->getAction(Array)
#3 /html/vendor/illuminate/html/FormBuilder.php(146): Illuminate\Html\FormBuilder->open(Array)
#4 /html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(219): Illuminate\Html\FormBuilder->model(Object(App\Models\Flyers\FlyerHeader), Array)
#5 /html/storage/framework/views/57d1e9f70b6e066d0f2d577d53327b36(8): Illuminate\Support\Facades\Facade::__callStatic('model', Array)
#6 /html/storage/framework/views/57d1e9f70b6e066d0f2d577d53327b36(8): Illuminate\Html\FormFacade::model(Object(App\Models\Flyers\FlyerHeader), Array)
#7 /html/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(42): include('/html/...')
#8 /html/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(58): Illuminate\View\Engines\PhpEngine->evaluatePath('/html/...', Array)
#9 /html/vendor/laravel/framework/src/Illuminate/View/View.php(135): Illuminate\View\Engines\CompilerEngine->get('/html/...', Array)
#10 /html/vendor/laravel/framework/src/Illuminate/View/View.php(106): Illuminate\View\View->getContents()
#11 /html/vendor/laravel/framework/src/Illuminate/View/View.php(80): Illuminate\View\View->renderContents()
#12 /html/vendor/laravel/framework/src/Illuminate/Http/Response.php(51): Illuminate\View\View->render()
#13 /html/vendor/symfony/http-foundation/Response.php(198): Illuminate\Http\Response->setContent(Object(Illuminate\View\View))
#14 /html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1229): Symfony\Component\HttpFoundation\Response->__construct(Object(Illuminate\View\View))
#15 /html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(113): Illuminate\Routing\Router->prepareResponse(Object(Illuminate\Http\Request), Object(Illuminate\View\View))
#16 [internal function]: Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#17 /html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#18 /html/app/Http/Middleware/RedirectIfNotBackOffice.php(32): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#19 [internal function]: App\Http\Middleware\RedirectIfNotBackOffice->handle(Object(Illuminate\Http\Request), Object(Closure))
#20 /html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#21 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#22 /html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#23 /html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(114): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#24 /html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(69): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(App\Http\Controllers\FlyerController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'edit')
#25 /html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(203): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'App\Http\Contro...', 'edit')
#26 /html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(134): Illuminate\Routing\Route->runWithCustomDispatcher(Object(Illuminate\Http\Request))
#27 /html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(708): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#28 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#29 /html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#30 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#31 /html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#32 /html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(710): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#33 /html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(675): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#34 /html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(635): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#35 /html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(236): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#36 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#37 /html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#38 /html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#39 /html/app/Http/Middleware/VerifyCsrfToken.php(17): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#40 [internal function]: App\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#41 /html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#42 /html/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#43 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#44 /html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#45 /html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(62): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#46 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#47 /html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#48 /html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#49 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#50 /html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#51 /html/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#52 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#53 /html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#54 /html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#55 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#56 /html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#57 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#58 /html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#59 /html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(122): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#60 /html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(87): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#61 /html/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#62 {main}
Presto's avatar

I just found this:

{!! Form::model($flyer, ['route' => ['flyers'], 'method' => 'patch', 'class' => 'form-horizontal']) !!}

I'm guessing I may need to change ['route' => ['flyers'] to something else???

bashy's avatar

You have it right there, FormBuilder.php. Used by something where you pass a named route to generate a URL or action.

#0 /html/vendor/illuminate/html/FormBuilder.php(803): Illuminate\Routing\UrlGenerator->route('flyers', Array)

Can you show your view file? See any url() action() Form::open() stuff?

Presto's avatar

You where correct, I needed to change ['route' => ['flyers'] to ['route' => ['flyers.edit'], thanks @bashy

bashy's avatar

Ah you replied with it before I submitted :) that's that sorted!

bashy's avatar
bashy
Best Answer
Level 65

If you've got a form you want to UPDATE, you need to PUT to flyers.update

That's the destination of flyers.edit form.

This should work (not sure if you need array around the route name).

{!! Form::model($flyer, ['route' => ['flyers.update'], 'method' => 'put', 'class' => 'form-horizontal']) !!}

You had the right idea but the PATCH one doesn't have a named route for it, which is why it errored.

Presto's avatar

Awesome, that did the trick

{!! Form::model($flyer, ['route' => ['flyers.update', $flyer->flyernum], 'method' => 'put', 'class' => 'form-horizontal']) !!}

Thanks for your help @bashy!

bashy's avatar

Oh yeah you do need to pass the item ID, sorry :)

1 like

Please or to participate in this conversation.