Can only instantiate this object with a string(Laravel)? - 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

Related

Error: Ziggy error: 'id' parameter is required for route

I am working on single SPA using laravel and inertia js. I am using multi language as well. So I am passing language as prefix parameter like this.
Route::group(['prefix' => '{language}'],function(){
Route::get('events',[HomeController::class,'event'])->name('events');
Route::get('events-details/{id}',[HomeController::class,'eventDetail'])
->name('events.reservations.index');
});
my controller
public function eventDetail($land,$id)
{
$events = $this->repository->getAllEvents();
$event_details = $this->repository->findById($id);
$time_interval = ReservationHelper::getTimeInterval();
return Inertia::render('Frontend/Pages/Reservation/Index', compact('events','event_details','time_interval'));
}
Calling in vue component like this
<Link
:href="
route('events.reservations.index', [$page.props.current_locale, id])
"
>
<div class="sao-box1 text-center">
<img :src="imgSrc" alt="" class="img-fluid rounded_img" />
<h3>{{ title }}</h3>
<div class="event-description" v-html="description"></div>
<a class="sl-btnBook">Book</a>
</div>
</Link>
when I click on that link I am getting error as
Error: Ziggy error: 'id' parameter is required for route 'events.reservations.index'
I don't know where I am going wrong.
thank you
change this line only from :-
:href="route('events.reservations.index', [$page.props.current_locale, id])"
to :
:href="route('events.reservations.index', {language : $page.props.current_locale, id: id})"
thanks

How to set up a beautiful url in laravel 8?

Now my url looks like this
localhost/3
But I want the path to look like this
localhost/some-text
To do this, I have a special url field in the Ad model, where the desired address is located. But going through it, I get 404
I have a route
Route::get('/{url}', [App\Http\Controllers\IndexController::class, 'show'])->name('show');
Method
public function show($url) {
$ad = Ad::where('url', $url)->first();
return view('ad', compact('ad'));
}
And btn
<a href="{{ route('show', ['url' => $ad->url]) }}">
<button type="button" class="btn btn-sm btn-outline-secondary">View</button>
</a>
To create better links just use slug
I use laravel slugable

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>

laravel : Pass information with key in url

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) }}">

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