How to create url with parameters in get request laravel - 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

Related

How to set custom route name before main route in 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');

Set tab name in redirect to route in laravel

in laravel 8 i will redirect the user to a route after doing the query.
There are many tabs on the page where I want the user to be transferred
I wrote the code like this
(Of course I know it's wrong, but I wanted to try, and yet I did not think of another way
return redirect()->route('admin.auth.user.show', $user . "#edit-information")->withFlashSuccess(__('The user was successfully updated.'));
I get an error with this code
What is your solution?
What you can do to activate for example bootstrap tab based on #web paramater is use the redirect() method like this:
return redirect()->route('backend.settings.show', ['eshop' => $eshop->id, '#homeImages']);
Eshop is regular route parameter but '#homeImages' is added to the end of the route which is then picked up by the js on page load.
In Laravel there is a withFragment method, which add a fragment identifier to the URL.
return redirect()->route('admin.auth.user.show', ['user' => $user])->withFragment('edit-information');
https://laravel.com/api/8.x/Illuminate/Http/RedirectResponse.html#method_withFragment

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

Codeigniter router get parameter

I use $.getJSON() to retrieve some data for a couple of cascading dropdowns in my form. $.getJSON() automatically appends the parameter at the end of the URL like domain.com/controller/method/?parent=5
So, I've declared my method like public function method($parent) which works file, but the same method will be used from other parts of the website that will call it like domain.com/controller/method/5
I tried to create a route in routes.php like the one below:
$route['business/regions/?parent=(:num)'] = 'business/regions/$1';
but it doesn't seem to work. Am I doing something wrong? Maybe ? is confusing the regex parser of the router? Do I have to escape it somehow to make it a 'literal' ? ?
Or is it that router is not used to 'rewrite' get parameters at all? I'm very confused, as it should work but it doesn't and I'm wondering what's wrong with it...
Codeigniter route parameters are for url parameters. It is particularly useful when trying to create a REST styled url pattern.
What you're trying to do is get url query string from the url which is not supported via the Codeigniter router. For you to get what you want you can do the following:
In your routes.php:
$route['business/regions'] = 'business/regions';
and in your controller Business.php:
public function regions() {
//the numeric id you're looking for
$parent = $this->input->get('parent');
}

passing data to another controller

I need to pass product Id from cart to custom controller, for example
http://**/catalogsearch/filter/results?product={ID}
I dont have a clue how to pass data like that using magento helpers etc
Thanks
I am assuming from your question that you are redirecting from one controller to another and would like to pass query parameters along?
The syntax would be:
$params = array('key' => 'value');
$this->_redirect('frontname/controlller/action', array('_query' => $params));
EDIT
To answer the question in the comment on how to get these parameters from a template:
First off, I would advise not to do this, you should be recieving parameters in the controller. So, your custom controller should be responsible for receiving any parameters.
Regardless, the code in either situation is the same:
All parameters…
$this->getRequest()->getParams()
Single parameter…
$this->getRequest()->getParam('parameter_name')

Resources