Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem routing a form to his respective controller #5

Closed
Fanan90 opened this issue Sep 23, 2015 · 8 comments
Closed

Problem routing a form to his respective controller #5

Fanan90 opened this issue Sep 23, 2015 · 8 comments
Assignees
Labels

Comments

@Fanan90
Copy link

Fanan90 commented Sep 23, 2015

Hi, im having a problem when I try to route a LaravelCollective form to his respective controller, this is the view which contains the form:

@extends('layouts.admin')
@section('content')
{!!Form::open(['route'=>'investigador.store', 'method'=>'POST'])!!}
<Here goes the form fields>
{!!Form::submit('Registrar',['class'=>'btn btn-primary'])!!}
{!!Form::close()!!} 
@endsection

And here my routes.php

<?php
Route::localizedGroup(function () {
    <Other routes>
    Route::resource('investigador', 'InvestigadorController');
});
Route::resource('login', 'LoginController');

When I route the login to the LoginController I don't have any problem because the login method does not need to be translated but when I try to open the view which contains the form I receive this error messages (server and project are example names):

InvalidArgumentException in UrlGenerator.php line 278:
Route [investigador.store] not defined.
in UrlGenerator.php line 278
at UrlGenerator->route('investigador.store') in FormBuilder.php line 943
at FormBuilder->getRouteAction('investigador.store') in FormBuilder.php line 898
at FormBuilder->getAction(array('route' => 'investigador.store', 'method' => 'POST')) in FormBuilder.php line 108
at FormBuilder->open(array('route' => 'investigador.store', 'method' => 'POST')) in Facade.php line 210
at Facade::__callStatic('open', array(array('route' => 'investigador.store', 'method' => 'POST'))) in 85a6f126a152415156083d060d88cd91 line 4
at FormFacade::open(array('route' => 'investigador.store', 'method' => 'POST')) in 85a6f126a152415156083d060d88cd91 line 4
at include('/server/project/storage/framework/views/85a6f126a152415156083d060d88cd91') in PhpEngine.php line 42
at PhpEngine->evaluatePath('/server/project/storage/framework/views/85a6f126a152415156083d060d88cd91', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag))) in CompilerEngine.php line 58
at CompilerEngine->get('/server/project/resources/views/investigador/create.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag))) in View.php line 138
at View->getContents() in View.php line 107
at View->renderContents() in View.php line 81
at View->render() in Response.php line 51
at Response->setContent(object(View)) in Response.php line 202
at Response->__construct(object(View)) in Router.php line 1225
at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 113
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
<etcetera>

and

ErrorException in UrlGenerator.php line 278:
Route [investigador.store] not defined. (View: /server/project/resources/views/investigador/create.blade.php)
in UrlGenerator.php line 278
at CompilerEngine->handleViewException(object(InvalidArgumentException), '1') in PhpEngine.php line 44
at PhpEngine->evaluatePath('/server/project/storage/framework/views/85a6f126a152415156083d060d88cd91', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag))) in CompilerEngine.php line 58
at CompilerEngine->get('/server/project/resources/views/investigador/create.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag))) in View.php line 138
at View->getContents() in View.php line 107
at View->renderContents() in View.php line 81
at View->render() in Response.php line 51
at Response->setContent(object(View)) in Response.php line 202
at Response->__construct(object(View)) in Router.php line 1225
at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 113
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(InvestigadorController), object(Route), object(Request), 'create') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'Project\Http\Controllers\InvestigadorController', 'create') in Route.php line 201
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 704
<etcetera>

The rest of the translated pages without forms work fine in all the languages.
Here you have the result of a php artisan route:list on my project.

+--------+----------+----------------------------------+----------------------+-------------------------------------------------------+----------------------------------------------------------------------+
| Domain | Method   | URI                              | Name                 | Action                                                | Middleware                                                           |
+--------+----------+----------------------------------+----------------------+-------------------------------------------------------+----------------------------------------------------------------------+
|        | GET|HEAD | /                                |                      | Project\Http\Controllers\HomeController@index           | localization-session-redirect,localization-redirect,localized-routes |
|        | GET|HEAD | admin                            |                      | Project\Http\Controllers\HomeController@admin           | localization-session-redirect,localization-redirect,localized-routes |
|        | GET|HEAD | auth                             |                      | Project\Http\Controllers\HomeController@auth            | localization-session-redirect,localization-redirect,localized-routes |
|        | POST     | investigador                     | investigador.store   | Project\Http\Controllers\InvestigadorController@store   | localization-session-redirect,localization-redirect,localized-routes |
|        | GET|HEAD | investigador                     | investigador.index   | Project\Http\Controllers\InvestigadorController@index   | localization-session-redirect,localization-redirect,localized-routes |
|        | GET|HEAD | investigador/create              | investigador.create  | Project\Http\Controllers\InvestigadorController@create  | localization-session-redirect,localization-redirect,localized-routes |
|        | PUT      | investigador/{investigador}      | investigador.update  | Project\Http\Controllers\InvestigadorController@update  | localization-session-redirect,localization-redirect,localized-routes |
|        | DELETE   | investigador/{investigador}      | investigador.destroy | Project\Http\Controllers\InvestigadorController@destroy | localization-session-redirect,localization-redirect,localized-routes |
|        | PATCH    | investigador/{investigador}      |                      | Project\Http\Controllers\InvestigadorController@update  | localization-session-redirect,localization-redirect,localized-routes |
|        | GET|HEAD | investigador/{investigador}      | investigador.show    | Project\Http\Controllers\InvestigadorController@show    | localization-session-redirect,localization-redirect,localized-routes |
|        | GET|HEAD | investigador/{investigador}/edit | investigador.edit    | Project\Http\Controllers\InvestigadorController@edit    | localization-session-redirect,localization-redirect,localized-routes |
|        | POST     | login                            | login.store          | Project\Http\Controllers\LoginController@store          |                                                                      |
|        | GET|HEAD | login                            | login.index          | Project\Http\Controllers\LoginController@index          |                                                                      |
|        | GET|HEAD | login/create                     | login.create         | Project\Http\Controllers\LoginController@create         |                                                                      |
|        | PATCH    | login/{login}                    |                      | Project\Http\Controllers\LoginController@update         |                                                                      |
|        | PUT      | login/{login}                    | login.update         | Project\Http\Controllers\LoginController@update         |                                                                      |
|        | GET|HEAD | login/{login}                    | login.show           | Project\Http\Controllers\LoginController@show           |                                                                      |
|        | DELETE   | login/{login}                    | login.destroy        | Project\Http\Controllers\LoginController@destroy        |                                                                      |
|        | GET|HEAD | login/{login}/edit               | login.edit           | Project\Http\Controllers\LoginController@edit           |                                                                      |
+--------+----------+----------------------------------+----------------------+-------------------------------------------------------+----------------------------------------------------------------------+

How can I solve this error message?, with the mcamara LaravelLocalizaton module i had the same error, I´ve cleared the caches and begin into a clean new project but i receive the same error.

Thanks in advance.

@arcanedev-maroc arcanedev-maroc self-assigned this Sep 23, 2015
@arcanedev-maroc
Copy link
Member

I did not tested the Route::resource() method with Localization package.

I'm gonna check this out and try to fix it if there is a bug.

Have you tried explicit routes and see if it fix your problem ?

@Fanan90
Copy link
Author

Fanan90 commented Sep 23, 2015

How can I try it? I'm newbie in Laravel

@arcanedev-maroc
Copy link
Member

Ok, give me extra time to test your case and try to find the issue.

The Route:resource() generate Restful routes for your controller (http://laravel.com/docs/5.1/controllers#restful-resource-controllers).

To be explicit is to create your routes manualy. I know it's a little bit pain in the A55, but (IMO) you have a total control and flexibility on your routes and you don't have to run php artisan route:list to see all your routes.

arcanedev-maroc added a commit that referenced this issue Sep 23, 2015
@arcanedev-maroc
Copy link
Member

Never mind, i fixed it.

Try to update the arcanedev/localization >= 0.5.4.

Let me know if it's OK.

@Fanan90
Copy link
Author

Fanan90 commented Sep 24, 2015

It works! Good job and thanks!

@arcanedev-maroc
Copy link
Member

You're welcome and thanks for your feedback 👍 .

@sabina2nistor
Copy link

sabina2nistor commented Dec 23, 2016

how did you solve this? please tell me step by step, i am having the same problem as you and i am also a beginner

@arcanedev-maroc
Copy link
Member

Are you using Route::resource() with localization ? Try to avoid that and using explicit routes like Route::get(), Route::post() ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants