How to set custom route name before main route in Laravel? - laravel

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');

Related

How to create url with parameters in get request laravel

I would like to create an url as shown below
/domain/url=cloud_hosting&name=cloud_hosting
this is the href url that I use in my blade
continue
but that href url is generating different route
/domain/cloud_hosting/cloud_hosting
I have tried this one:
Continue
and that's working fine. But is there any other way which is nice and beautifull?
Thank you
you can do something like below. simply make a get request as in Web.php
Route::get('domain')
and can use it like below and can pass multiple query strings:
continue
You can also use the query method:
url('domain', Arr::query(['url' => request()->segment(2), 'name' => $page_name]))
// /domain/url=cloud_hosting&name=cloud_hosting

Getting the URL details - Laravel

I am working on a Laravel project, where I want to toggle partials based on the URL data like
foo.bar.com/#itemone/create
foo.bar.com/#itemone/view
Basically, I want to pass whether it is create or view to the partials like this
#include('partials.layouts._core_activity_header',['layout_type' => "create"])
How do I achieve this? Any help would be appreciated.
you can use the route name
Route::getCurrentRoute()->getName()
this will return the route alias

LARAVEL ROUTES not accept

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.

codeigniter with same route name with different controller functions

I want to keep routes like this
$route["signup"] = "Controller/signup";
$route["signup"] ="Controller2/fbsignup";
Is it possible to to give same route names with different controller functions.
Then how ?
No, you can't.
If you write same route again, it will overwrite first one.
It is just like an array variable.
If you assign any other value to variable, first one will overwrite.
But you can specify HTTP method with route.
No you can't do like this, you are going to make api then define method that will help
$route["signup"]["post"] = "Controller/signup";
$route["signup"]["GET"] ="Controller2/fbsignup";
I want to keep routes like this
$route["signup"] = "Controller/signup";
$route["signup"] ="Controller2/fbsignup";
then try this in routes and url should be like signup/signup and signup/fbsignup
$route["signup/signup"] = "Controller/signup";
$route["signup/fbsignup"] ="Controller2/fbsignup";
call the url like
signup/signup
signup/fbsignup

how to pass variable from view to route in laravel

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.

Resources