I have the following route :
Route::post('new-password/{id}/{random}',['as'=>'postNewPassword','uses'=>'AbcController#postNewPassword']);
And I am using that route in form action and passing the required parameters like:
action="{{ route('postNewPassword',Request::segment(2),Request::segment(3))}}"
The Url is :
http://localhost:8080/new-password/14/yxbH1sP4mdRngtCqQ9VS1KeksadOf5Piwc784HeQ
I don't know what am I missing. What am I doing wrong here?
You need to pass all route paramters as the seconds parameter, so change code to:
route('postNewPassword', [Request::segment(2), Request::segment(3)])
Related
This is my url :
http://localhost:8000/password-reset?token=$2y$10$N8AX4N9XMhP4NKPCK6NtjOvwoOzeWmaQnOJkxrKg4Ul7shNhp0zdu
This is how my route looks like:
Route::get('password-reset?token={token}', 'Auth\PasswordResetController#index');
However this is not getting captured in the controller.
Change the route first part to password-reset (remove ?token={token}) and then in controller use request('token') to get the token value.
I tried to create a new route with a controller that uses an id parameter, and a link to this.
The error is when I try to create a link to a controller.
The error that I got is:
"Missing required parameters for [Route: notas.detalle] [URI: detalle/{id}]. (View: /var/www/html/laravel/blog/resources/views/producto.blade.php)"
The route:
Route::get('detalle/{id}', 'productoController#detalle')>name('notas.detalle');
The blade template:
#foreach($notas as $nota)
{{$nota->id}}
{{$nota->created_at}}
{{$nota->updated_at}}
#endforeach
What can be the problem?
Laravel route helpers can take as a second parameter, an associative array with all the keys (require parameter) and it values.
so is your case it would be something like this
route('notas.detalle', ['id' => 1])
but it could be multiple parameter so is your route had something like 'notas/{id}/student/{student}
then you could do the following.
route('notas.detalle', ['id' => 1, student => 129483])
here is a link to the docs where you can see this in more details.
https://laravel.com/docs/5.8/routing#named-routes
The problem is that the variable must be after comma.
I think this will work:
{{$nota->id}}
I am trying to get a value from the url that looks more or less like this:
http://localhost:8000/new-user/7
This number 7 passed in the url as a parameters is an ID in which i submit from the blade form as a request for an action i perform in the controller but i cant get this value in anyway.
This is what i tried so far:
I tried to use this in the controller in which i submitted the form
$request->route('company_id');
I also tried to get this as a proper GET parameter:
<input type="hidden" name="company_id" id="company_id" value="{{app('request')->input('company_id')}}">
and i also tried this:
<input type="hidden" name="company_id" id="company_id" value="{{Input::get('company_id')}}">
and this:
<input type="hidden" name="company_id" id="company_id" value="{{$_GET['company_id']}}">
None os these options work and i still receive an empty value.
Any ideas or suggestions on how can i get this variable?
Thank you!
A route parameter and a query parameter are two different things.
If you have a route defined like this:
/** routes/web.php */
Route::get('/new-user/{id}', 'UsersController#show');
In this case $id is a route parameter. So to get in your blade view you could do:
/** resources/my_view.blade.php */
{{ request()->id }}
So, with a request like the one you used http://localhost:8000/new-user/7 that should output: 7.
Another case is when you have a query param. These variables doens't need to be defined in the route. For example a call of this type, using the same route defined in the previous example:
GET http://localhost:8000/new-user/7?foo=bar
^^^^^^^^
In this case the foo=bar can be accessed like this:
{{ request()->query('foo') }} // 'bar'
I'm trying to create a route with an array of aliases, so when I call whois or who_is in the url it goes to the same route.
Then I don't need to keep repeating the code every time, changing only the alias.
I tried the code below.
Variables in the routes:
$path = 'App\Modules\Content\Controllers\ContentController#';
$aliases['whois'] = '(quemsomos|who_is|whois)';
Routes:
Route::get('{whois}', array('as' =>'whois', 'uses' => $path.'getWhois'))->where('whois', $aliases['whois']);
this one works as well
Route::get('{whois}', $path.'getWhois')->where('whois', $aliases['whois']);
Typing in the url my_laravel.com/whois or my_laravel.com/who_is or my_laravel.com/quemsomos will send me to $path.'getWhois' (which is correct).
But when I try to call it in the html on blade...
Who we are
The reference link goes to my_laravel.com//%7Bwhois%7D
How could I call route('whois') on my blade.php and make it work like when I type it on the url ?
I would like to use the route function` in my blade, so I can keep a pattern.
During route generation using the route function, Laravel expects you to set the value of the route parameter. You are leaving the parameter whois empty so the parameter capturing {whois} will not be replaced and results in the %7B and &7D for the accolades.
So in order to generate a route you will need to define what value you'd like to use for whois; {{ route('whois', ['whois'=>'whois']) }} for instance.
I couldn't get it to work on symfony 1.4.5
I have a route :
edit_page:
url: /editpages/:page
param: { module: pages, action: edit }
and I want to get to url with a url_for() helper.
<a class="float-right rounded-btn" href="<?php echo url_for('#edit_page'); ?>">Configure</a>
this one just is giving me and :
The "/editpages/:page" route has some
missing mandatory parameters (:page).
When error message tells that "route has some missing mandatory parameters", it is a clear sign that you have to add missing mandatory parameters to the route. :)
url_for('#edit_page?page=configure');