error:
Missing required parameters for [Route: pesquisaavan] [URI: pesquisa/{pesquisa}/{ordem}]. (View: C:\xampp\htdocs\1.1.2\resources\views\pesquisa.blade.php)
route:
Route::get('pesquisa/{pesquisa}/{ordem}', $controller.'pesquisaavan')->name('pesquisaavan');
route in html :
value="{{ route('pesquisaavan','teste','precoasc')}}"
the page without this route in the view works perfectly, so the route in the view will have some problem that will make this error, and I assume I have everything that is needed in the route in the view
route() helper takes an array of the route parameters, which has to be named in regards to the route parameters name as defined eg. {pesquisa}.
route('pesquisaavan', ['pesquisa' => 'teste', 'ordem' => 'precoasc'])
Related
I'm trying to do my first attachment/ detachment. I'm using two tables, user, event, and its pivot, event_user. For this one, I needed to do a button to subscribe the user to an event, so my teacher told me to use an and route it to the method subscribe. At this moment, the error that comes up is.
Route [subscribe] not defined.
Blade
<a href="{{ route('subscribe', $event->event_id) }}"
class="btn btn-primary btn-lg">Subscribe</a>
Route
Route::get('/subscribe', [SubscribeController::class, 'index']);
SubscribeController
public function index($id)
{
$user = Auth::user();
$user->events->attach($id);
return view('index');
}
I tried putting URL instead of the route in the , and it goes to /subscribe, but comes to an error that says -> Too few arguments to function 0 passed and exactly 1 expected.
I did a dd() in the component to see if the event id was the correct one, and it was. Also, apart from these errors, how can I route a method without changing the route? Can I do it using the indexController (because it's in the index where these events are located)?
First, in order to reference the route by name, you need to give it the name subscribe.
Docs: https://laravel.com/docs/master/routing#named-routes
Second, you want to add that id route parameter that you are trying to use in your controller.
Docs: https://laravel.com/docs/master/routing#required-parameters
So your route should end up looking like this:
Route::get('/subscribe/{id}', [SubscribeController::class, 'index'])
->name('subscribe');
And then you'll want to call it like this:
<a href="{{ route('subscribe', ['id' => $event->event_id]) }}"
Firstly in your blade view file you are trying to generate url using route helper like this
<a href="{{ route('subscribe', $event->event_id) }}"
class="btn btn-primary btn-lg">Subscribe</a>`
The way you call the route helper we can supposed this
You have already define a route in your web.php file which is named subscribe
and that route have paramater
But in your web.php file you have this route
Route::get('/subscribe', [SubscribeController::class, 'index']);
This route doesn't have any name.
And it doesn't expect any parameter
To fix that you should only change the way you have define you route in the web.php file like this
Route::get('/subscribe/{id}', [SubscribeController::class, 'index'])
->name('subscribe');
With this route we define:
id as a required parameter
And the route is named subscribe
First of all, I would like to say that my English is not so good and is my first time posting here, so excuse me if I did something wrong! Well, I am starting practicing with Laravel and I am trying to create a URL for users can like posts. my URL and controller is right now this Route::post('/post/{post}/like', [LikeController::class, 'postLike'])->name('post.like'); where post is the posts id that i am trying to pass through my form action attribute. Here is my form:
#props(['id'])
<div {{ $attributes->merge(['class' => 'card-footer d-flex justify-content-around']) }}>
<form action= "{{ route('post.like' , $id) }}" method="post" >
#csrf
<button>submit</button>
</form>
</div>
If you wonder if the id is not actually passed into the component, I checked {{ dd($id) }} and it printed it.
My controller is this which it doesn't actually do anything right now. I am just trying to pass the id:
class LikeController extends Controller
{
public function postLike(Post $post) {
dd($post);
}
}
After all this i am getting the error:
Missing required parameter for [Route: post.like] [URI: post/{id}/like] [Missing parameter: id]. (View: blog\resources\views\components\post\interaction.blade.php)
I am having two days to find the problem and I am still trying this moment I am sending this... I can't found where is the mistake! If you could help me would be much appreciated! Ty in advance
You need to pass the ID as an associative array in your route().
{{ route('post.like', ['id' => $id]) }}
If the named route defines parameters, you may pass the parameters as the second argument to the route function. The given parameters will automatically be inserted into the generated URL in their correct positions and you should name 'post' instead of 'id':
Route::post('/post/{post}/like', [LikeController::class, 'postLike'])->name('post.like');
And you can call this route anywhere
route('post.like', [$postId])
If that still doesn't work for you. Then it might be issue of Route Cache Run:
php artisan route:clear
Use same name parameter
When you use "id" keyword as a parameter in web.php then also same name pass in function argument in the controller
Route::post('/post/{id}/like', [LikeController::class, 'postLike'])->name('post.like');
Controller
class LikeController extends Controller
{
public function postLike(Post $id) {
dd($id);
}
}
Sorry for my bad English.
I have no idea this could be the problem but after many changes i cast the id of the post into an integer and it actually worked <form action= "{{ route('post.like' , (int)$id) }}" method="post" > . I don't know why i should cast the id into an integer because its already an integer by default and i checked that with {{ dd(getType($id)) }} and printed "integer"! I am really confused but it works! But i am not happy because i have no idea why i should cast an integer into an integer to make it work! Doesn't make any sense! If anyone has an answer to this would be great!
I got an error "Missing required parameters for Route" although I used a correct. Who can support me, please?
Route::Group(['prefix' => 'shop'], function () {
Route::get('product_page/orderby/{pa1}/rangeform/{pa2}/rangeto/{pa3}/type/{pa4}', ['as' => 'product_page', 'uses' => 'shopcontroller#product_page']);
});
public function product_page($orderby,$rangeForm,$rangeTo,$type){
// do something
}
<a href="{{ route('product_page',['orderby'=>'1','rangeto'=>'50000','rangeform'=>'500000','type'=>'1']) }}"><img src="/source/images/p1.jpg" class="img-responsive" alt="" />
"Missing required parameters for [Route: product_page] [URI: shop/product_page/orderby/{pa1}/rangeform/{pa2}/rangeto/{pa3}/type/{pa4}]. (View: E:\shopmarket\resources\views\shop\product.blade.php)"
The parameter name in function should be same as in url {var}
public function product_page($pa1,$pa2,$pa3,$pa4){
// do something
The params in your route and your function should match (either names and number of params). In your case, you have 8 params -instead of 4-, the product_page function should look like:
public function product_page($orderby,$rangeform,$rangeto,$type){
// do something
}
and change the Get Router like (with optional params):
Route::get('product_page/{orderby?}/{rangeform?}/{rangeto?}/{type?}', ...
});
Also make sure when you buld your URL that your resulting URL is build according, it should be:
/product_page?order_by=1&rangeform=50000&rangeto=50000&type=1
Hope it helps!
I have created an app for multiple locations where i have location code in the url and the user can change the country. However, i have a issue with the urls i.e., with the hrefs
web.php
group(['prefix' => '{country}', 'middleware' => 'country'], function(){
Route::get('/', 'Frontend\PagesController#index')->name('welcome');
Route::get('/about', 'Frontend\PagesController#about')->name('about');
});
in my layouts/app.php menu i have <a href="{{ route('about') }}">
But i get an error
Missing required parameters for [Route: about] [URI: {country}/about]. (View: D:\xampp\htdocs\ezcures\ezcures\resources\views\layouts\app.blade.php) (View: D:\xampp\htdocs\ezcures\ezcures\resources\views\layouts\app.blade.php)
How to solve this?
The way you've set your routes up (by specifying a route group that requires a parameter {country}), a URL to an about page would take the following format:
https://yourdomain.com/{country}/about
When you're trying to generate a URL for an about page, you're not telling Laravel what to put in place of {country} (which is a required parameter), which is why you're seeing that error.
The resolution is to simply pass a parameter to the route() function call, like this:
<a href="{{ route('about', ['uk']) }}">
Which will generate a URL like:
https://yourdomain.com/uk/about
I have a MethodNotAllowedHttpException with a button for a post method , it's really strange because i made the same process with a lot of others things in the project but with this route don't want to work . Where i made a mistake ?
thanks a lot in advance friends :)
Here my route :
Route::post('licencies_to_update/{id}', 'LicencieController#Renouveller')->name('licencie.renouveller');
Here my button in my blade view :
{!! link_to_route('licencie.renouveller', 'Effectuer le Renouvellement' , [$licencie->id], ['class' => 'btn btn-primary']) !!}
Here the begin of my controller :
public function Renouveller(Request $request, $id)
{
$licencie = Licencies::findOrFail($id);
dd($licencie);
....
Use:
Route::get('licencies_to_update/{id}', 'LicencieController#Renouveller')
->name('licencie.renouveller');
instead of POST method. Because in the link of your button you are not requesting the url with a POST method but GET method. Besides, you are not doing anything related to POST variable. You are passing a simple variable id in your route param. So, no need to use POST param here.
The link you are creating is an anchor to the route you provided, but the link is a GET request, while you specify in your routes file that you want POST requests on that url.
Either create a form or change the method that route accepts (or let it also accept GET requests)
Edit:
Change your route to
Route::get('licencies_to_update/{id}', 'LicencieController#Renouveller')->name('licencie.renouveller');
to have the expected result the fastest!