and it works:
im add route and have view:
and errors:
wtf??? only copy paste, and rename...
Check layouts/app.blade.php There's something like route('qwe') and this route doesn't exist at all. So delete it from the layout and it should work.
Update
You're calling route('kwe') but you didn't name the route in the file. so add a name method to your route like the following.
Route::get('kwe', function(){
return view('kwe');
})->name('kwe');
Update 2
route helper's parameter is the route name not its path. So you need to name the route before calling it using route helper.
If you wanna use the path itself instead you can use url helper.
Related
I want to add username before each route..
ex:
sam/productDashboard
james/productDashboard
note - Username is getting from session.
i tried like this. it doesn't work
Route::get( session()->get('name').'/productDashboard',[ProductController::class,'ProductDashboard'])->name('productDashboard');
This is not the way to use variable inside a route.
Do it like this:
Route::get('{username}/productDashboard',[ProductController::class,'ProductDashboard'])->name('productDashboard');
and when you are referencing to this route with a link do it this way:
<a href="{{route('productDashboard',['username' => session()->get('name')])}}">Link</>
it registered on the start you can't do in this way
You could set it like params
Route::get('{username}/productDashboard',[ProductController::class,'ProductDashboard'])->name('productDashboard');
How can I use a resource controller at the root of my website? I have tried:
Route::resource('/', CategoryController::class);
But no luck.
Normally, you wouldn't do this as the first argument to that method is a resource name, not a path. Though, you can do this if you really want to by overriding the name of the route parameter that ends up getting used:
Route::resource('/', YourController::class)->parameters(['' => 'category']);
This would create the routes with a parameter named 'category':
GET {category} show
GET {category}/edit edit
PUT|PATCH {category} update
...
If you wanted to you could also update the names of these routes if needed via the names method.
I'm setting up a new route system.
Route::get('/{cat1Url}', 'CategoryController#showCat1')->name('showCat1');
Route::get('/{productUrl}', 'ProductController#showProduct')->name('showProduct');
My sef link is after "/"
But,
{{ route('showProduct',[$p->pr_url]) }}
This method not working with route name. Working only upside route.
I don't want use
"/cat/myVariable"
or
"/product/myVariable"
Can't I use route name to work this way?
What is the solution to this?
In this way, if you make a get request to /something the laravel you start from top of web.php file looking to a route that follows the pattern. Your both routes will follow that pattern, but the laravel will always, pass the first one to controller.
You have two options:
Put only one route, and inside the controller you switch to the appropriate function. But this isn't a great ideia, because this is the function of the Web.php.
Use the routes like the documentation recommend:
Route::get('/cat/{catId}', 'CategoryController#showCat')->name('showCat');
Route::get('/prod/{productId}', 'ProductController#showProduct')->name('showProduct');
and in Controller you make the appropriate handler of your Category or Product.
You will have to have a way to tell Laravel which url to be mapped to what otherwise it will always use the last defined route. So in your case calling /myVariable and /myVariable it will use the latest definition which is showProduct. The only other way is if you use regular expression to differentiate the variables. For example:
Route::get('/{cat1Url}', 'CategoryController#showCat1')
->name('showCat1')->where('cat1Url', 'cat-*');
Route::get('/{productUrl}', 'ProductController#showProduct')
->name('showProduct')->where('productUrl', 'prod-*');
This way your slugs need to start with what you define, but you cannot use just id as a numeric value for both.
The documentation says:
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 URL in their correct positions:
Route::get('user/{id}/profile', ['as' => 'profile', function ($id) {
//
}]);
$url = route('profile', ['id' => 1]);
If i do have a nested resource route by using Route::resource(...) twice, i will get a named route wich contains a placeholder like
employees.{employee}.images.index
How can i create a route for this nested resource using the blade templating engine?
I thought about
route('employees.{employee}.images.index', ['employee' => $employee->id]);
but that does not work. I know i can "manually" create the routes, but this will make them less maintainable.
Update 1
I know i can name the routes manually and then use the given name. But if there is a way without naming them i would prefer it.
You don't have to add anything like employee into a route name. Run php artisan route:list command and you will see real names of all routes (look at column called Name), created by resource clause. Then just use them like usual:
route('employees.images.index', ['employee' => $employee->id]);
Also, you can name resource routes.
How to pass a variable from view to route in Laravel?
Here's the code at my route.php:
Route::get('/{id}/{id1}', 'WelcomeController#index');
And at welcome.blade.php:
< a href="{{URL::route('/{4}/{5}')}}">test</a>
I want to build a link referencing the route above.
A good approach to do it would be to name your route and then reference it by name, passing the parameters needed. Here is how:
At routes.php:
Route::get('/{id}/{id1}', ['as' => 'welcome_index', 'uses' => 'WelcomeController#index']);
And at your view, you can do this:
test
Notice that the first parameter represent the route name and the second, the parameters for your URL. You can read more here.
The advantages of naming a route is that you can change your route path later and your URL will still work with the code above.