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!
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
i am new in laravel i made CRUD for some services. when i try to edit any one i have this error
Missing required parameter for [Route: services.update] [URI: dashboard/services/{service}] [Missing parameter: service].
my code to take data to edit it
<a href="{{route('services.edit', $service->id)}}">
my code in editing page {{ $service->id }}
and when i write in form to update in the editing page action="{{ route('services.update', $service->id) }}"
i got the error
and the code of edit in controller
public function edit(Service $service)
{
return view('dashboard.EditService', compact('service'));
}
in my rout page >>
Route::group(['prefix'=>'/dashboard' ], function () {
Route::get('/', function () {
return view('dashboard/index');
});
Route::resource('/services', 'App\Http\Controllers\ServiceController');
});
'Service' and 'Services' (with an 's' at the end) are different things according to laravel.
Try change your web.php file route parameter.
Before
Route::get('dashboard/services/{service}', [Controller::class, 'function']);
After
Route::get('dashboard/services/{services}', [Controller::class, 'function']);
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 want the user to download a file and it doesn't really need to be via ajax, but it was the easiest way I found, but it's not working.
Here is my method from the Controller that I'm calling:
public function download(Request $request)
{
$dir = $request->get("directory");
return response()->download($dir);
}
Here is my ajax function:
function download(diretorio) {
$.ajax({
url: "/panel/download",
data: {_token: jQuery(".token").val(), diretorio: diretorio},
success: function(e) {
}
}).done(function(e) {
});
}
This function is being called inside this append:
$('#uploads tbody').append("<tr><td>" + fileName + "</td> <td><a class='btn btn-success' href='' onclick=\"download('" + item + "')\">Download</button></td></tr>");
});
Here is my route, which is inside a group called panel:
Route::get('/download/', ['as' => 'files.download', 'uses' => 'Panel\ClientController#download']);
My first question is: Is it possible to make this call from ajax to a download response from laravel?
Second question: I cannot figure out how to replace the ajax call for a route to a laravel controller, is it possible?
Thank you!
Yes it is possible. This is just with Laravel only though. Try this example:
HTML: (just call your GET route here)
download file(s)
Download Function
public function download()
{
// $pathToFile : set to what you need
return Response::download($pathToFile);
}
due to the fact that the directory path parameter has slashes, I think the route is expecting other parameters. So I decided not to pass the entire directory path, but only an ID and the name of the file. So my route became like this: Route::get('/download/{id}/{fileName}', ['as' => 'files.download', 'uses' => 'Painel\ClienteController#fazerDownload']);
And it worked. Thank you for the answers and efforts!
I may be being thick but I am continually getting a page notfoundexception .
In a view I have the following:
<a href="{{ route('/galleryimages/{id}') }}"
This part is OK. In web.php I have:
Route::get('/galleryimages/{{id}}', function($id){
return view('gallery_pictures.pictures',['id'=>$id]);
});
The page pictures definitely exists in the subdirectory gallery_pictures.
Your route is incorrect, Laravel route parameters use one curly braces, like so: {id}. Rather than {{id}}
The helper function you are using accepts route names not route URL's, to link routes you should use the url() function
https://laravel.com/docs/5.3/helpers
https://laravel.com/docs/5.3/routing
I've provided you some for reference links if you haven't already checked them out.
HTML Fix:
My Link
Route Fix:
Route::get('/galleryimages/{id}', function($id) {
return view('gallery_pictures.pictures', ['id'=> $id]);
});
A little extra
If you want to use the route function you must set a name for your route, you can do it as so:
Route::get('/galleryimages/{id}', function($id) {
return view('gallery_pictures.pictures', ['id'=> $id]);
})->name('gallery_images');
Then you may access the route by doing something like so
My Link