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

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

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

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 returns 404 error when passing a parameter

Hello when I send a data press a link to show another view laravel returns a 404 error, what am I failing?, I have created other crud and I have had no problems so far
Expansion -> index.blade.php:
<a href="{{url('/cards/'.$expansion->exp_id.'/vcards')}}"class="btn btn-primary form-control" >Go!</a>
URL:
http://localhost/CardSystem/cartas/1/vcards
Route:
Route::resource('cards', 'cardControllerr');
cardController:
public function vcards($id){
$data['cards']= DB::table('cards')
->join('expansion','expansion.exp_id','=','cards.exp_id')
->select('cards.card_id','cards.card_nom','expansion.exp_nom')
->where('cards.exp_id','=',$id)
->orderBy('cards.card_num')
->paginate(5);
return view('cards.vcards',$data);
vcards.blade.php:
#extends('layouts.app')
#section('content')
<div class="container">
#foreach($cards as $card)
<div class="form-group">
<h5 class="card-title">{{$card->card_nom}}</h5>
</div>
#endforeach
</div>
#endsection
I think you misunderstood routing, views etc.
For your controller to be hit, you will need to make the following route.
Route::get('cartas/{card}/vcards', 'cardControllerr#vcards')->name('cartas.vcards');
If you wanna link to this route use route().
route('cartas.vcards', ['card' => $card]);

Data retrieving Using Rest Web services by angular js is not happing

Here is section of code applied on
<div class="container" data-ng-app="myApp" ng-controller="hController">
<li ng-repeat="x in names">
{{ x.Name + ', ' + x.Country }}
</li>
</ul>
Controller Implementation
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://localhost:8080/rest/hotel")
.success(function(response) {$scope.names = response.records;});
});
</script>
</head>
Error i can see in web console
Error: [ng:areq] http://errors.angularjs.org/1.3.14/ng/areq?p0=hotelController&p1=not%20a%20function%2C%20got%20undefined
at Error (native)
at http://localhost:8080/resources/js/angular.min.js:6:417
i have already added angular.min.js in path
conflicts in naming of your controllers
app.controller('customersCtrl'....)
and in the Template you have used "hController"
<div class="container" data-ng-app="myApp" ng-controller="hController">
Use the same name in both the places or else angular doesn't find the the directive ng-controller defined in your Template and hence produces error out . ng-controller is a angular built-in directive which attaches controller to the view .

Laravel:Passing variable from controller to view

chatcontroller.php function returns variable to view:
public function getChat()
{
$message = chat_messages::all();
return View::make('home',compact($message));
}
this is my route:
Route::get('/getChat', array('as' => 'getChat','uses' => 'ChatController#getChat'));
this is my home.blade.php:
#extends('layouts.main')
#section('content')
<div class="container">
<h2>Welcome to Home Page!</h2>
<p> <a href="{{ URL::to('/logout') }}" > Logout </a></p>
<h1>Hello <span id="username">{{ Auth::user()->username }} </span>!</h1>
<div id="chat_window">
</div>
<input type="text" name="chat" class="typer" id="text" autofocus="true" onblur="notTyping()">
</div>
<ul>
#foreach($message as $msg)
<li>
{{ $msg['sender_username']," says: ",$msg['message'],"<br/>" }}
</li>
#endforeach
</ul>
<script src="{{ asset('js/jquery-2.1.3.min.js') }}"></script>
<script src="{{ asset('js/chat.js') }}"></script>
#stop
I am trying to send result returned by select query to view from controller.
when I do this from homecontroller.php then it works fine.
if I try to pass from controller which I have defined it gives error message as:Undefined variable.
I have used the extends \BaseController do i need to do anything else to access my controller variable from view.
please suggest some tutorial if possible for same.
Verify the route to be sure it uses the new controller:
Route::get('user/profile', array('uses' => 'MyDefinedController#showProfile'));
First of all check your routes, as Matei Mihai says.
There are two different ways to pass data into your view;
$items = Item::all();
// Option 1
return View::make('item.index', compact('items'));
// Option 2
return View::make('item.index')->with('items', $items); // same code as below
// Option 3
View::share('item.index', compact('items'));
return View::make('item.index);
You can also do this:
$this->data['items'] = Item::all();
return View::make('item.index', $this->data);

Resources