laravel : Pass information with key in url - laravel

Hello i want to make url like example.com/overview-schedule?=user_key=123456 in laravel. I do not know how to do it.
Sharing my code :
In blade.php define a link
<a href="{{ route("overview-schedule") }}">
on my web.php
Route::any('overview-schedule', 'Front\PlanController#scheduleOverview')->name('overview-schedule');
Got an error
InvalidArgumentException
Route [overview-schedule?user_key=123456] not defined.
How can i do it ?

use url() helper method
$user_key = 123456;
<a href="{{ url('/overview-schedule?user_key='.$user_key) }}">

You can pass an array of parameters to route function :
<a href="{{ route("overview-schedule" , ['user_key' => $user_key]) }}">

You should try this:
<a href="{{ url('/overview-schedule?user_key='.$user_key) }}">

Related

Can only instantiate this object with a string(Laravel)?

I get this error when I call route.
I give a route Like:
<a href="{{ route('billing', ['plan' => $plan[0]->id]) }}">
<button style="padding:15px 25px;border:none;color:#007F5F;font-weight:700;font-size:20px;border- radius:10px;">Choose Plan</button>
</a>
but When I click on link I get this error : Laravel Error Picture
This is my Route:
if (Util::registerPackageRoute('billing.process', $manualRoutes)) {
Route::get(
'/billing/process/{plan?}',
BillingController::class.'#process'
)
->middleware(['verify.shopify'])
->where('plan', '^([0-9]+|)$')
->name(Util::getShopifyConfig('route_names.billing.process'));
}
I can't understand this error please help me to solve this error.
I solved my error by adding shop parameter on the route :
My route Now :
<a href="{{ route('billing', ['plan' => 2, 'shop' => Auth::user()->name]) }}">
<button style="padding:15px 25px;border:none;color:#007F5F;font-
weight:700;font-size:20px;border-radius:10px;">Choose Plan</button>
</a>
This route works fine: 😊😊😊
Check out relevant issue: https://github.com/gnikyt/laravel-shopify/issues/872

Missing required parameters for [Route: about]

I installed cviebrock/eloquent-sluggable package.
I have an issue with the URLs i.e., with the hrefs and slug.
menu.blade.php
<a class="nav-link" href="{{ route('about') }}">
web.php
Route::get('content/{contentSlug}', 'PageController#content')->name('about');
RouteServiceProvider.php
Route::bind('contentSlug', function ($value) {
return Page::whereSlug($value)->firstOrFail();
});
I get this error
Illuminate\Routing\Exceptions\UrlGenerationException
Missing required parameters for [Route: about] [URI: en/content/{contentSlug}]. (
This is because you don't pass {contentSlug} value in route.
<a class="nav-link" href="{{ route('about',['contentSlug' =>'Hello']) }}">
If you want to make route with optional parameter then use ? .{contentSlug?}

How to pass multiple arguments with url (routing) in laravel

I am trying to pass argument on route but unfortunatly i am facing error please help me thanks.
Missing required parameters for [Route: products.detail] [URI:
products/{slug}/{id}/details]. (View:
/home/zubair/htdocs/wallmasterfurnishing.com/web/resources/views/wallpapers-product.blade.php)
let detailurl = '{{route("products.detail",[":slug",":id"])}}';
productdetail = detailurl.replace(':slug', element.slug);
productdetail = detailurl.replace(':id', element.id);
<a href="${productdetail}">
<h4 class="prodcardtitle">${element.code} - ${element.name}</h4>
</a>
It seams like you are combining Blade template with Javascript
let detailurl = '{{route("products.detail",[":slug",":id"])}}';
let keywords is part of JavaScript
and {{ route("products.details", [$element->slug, $element->id] }} is only available inside of blade template
As you are inside of javascript and not in blade template you should create the url using template literals and replace all placeholder with the the related value like this
let detailurl = `/products/${element.slug}/${element.id}/details`;
`<a href="${productdetail}">
<h4 class="prodcardtitle">${element.code} - ${element.name}</h4>
</a>`
You can pass multiple parameter to route as an array
<a href="{{ route('products.detail', ['slug' => $slugVariable, 'id' => $idVariable]) }}">
<h4 class="prodcardtitle">${element.code} - ${element.name}</h4>
</a>
for more info visit
Thanks
try with route name :
Route::get('products/{slug}/{id}/details','ProductController#productDetail')->name('productDetail');
<a href="{{ route('productDetail', ['laptop-slug','2']) }}">
<h4 class="prodcardtitle">${element.code} - ${element.name}</h4>
</a>

How to define a link in laravel?

Hello I am new bee in laravel. I have an <a> tag. I want to give link in controller. I wrote
<a href="{{ URL::to('/controller'); }}">
But it prints same in addressbar:
http://localhost:8000/{{ URL::to('/CategoryController'); }}
My routes.php file is OK.
Should i need to change in any other file ?

Laravel route not defined error even though it is

I have the following blade code:
<a href="{{ route('settings') }}">
<span class="title">Settings</span>
</a>
I have the following defined at the top of my routes.php file:
Route::post('settings/update', 'SettingsController#update');
Route::resource('settings', 'SettingsController');
When I try to go to any page with route('settings') I get a Route [settings] not defined error.
If I do php artisan routes I can see that the settings routes are all there as expected.
With route('settings') you refer to a route named settings but you don't have such a route. RESTful routes will automatically receive a route name though.
For the index method it is resource.index for the show method resource.show and so on.
Change your code to this:
<a href="{{ route('settings.index') }}">
<span class="title">Settings</span>
</a>
Change {{ route('settings') }} to {{ URL::to('settings') }}

Resources