Laravel blade: Unable to get id from object in url - php

i am working on eCommerce project where i got stuck with a issue. i am using url() to generate my url. i have a following code.
<a style="cursor: pointer;" href='{{ url("search?category=$categories[$i]->id")}}' class="menuLinks leftCategoriesProduct"> <span class="catText">{{($categories[$i]->name)}}</span></a>
on click i require
http://localhost/a2z/public/search?category=5
it worked on my one of the blade in the same project but here it generate a different url :
http://localhost/a2z/public/search?category={%22id%22:5,%22name%22:%22All%20Offers%22,%22slug%22:%22all-offers%22,%22user_id%22:2,%22parent_id%22:null,%22deleted%22:0,%22created_at%22:%222017-04-10%2013:21:48%22,%22updated_at%22:%222017-04-10%2013:21:48%22,%22childs%22:[]}-%3Eid
Here it returns the whole object however i need only the category id
I am not sure where i am doing wrong, is there a concatenation problem, or something related to blade which i am missing.
Help will be appreciated, Thanx

code:
{{ url('search') }}?category={{ $categories[$i]->id }}

I think you can try this:
<a style="cursor: pointer;" href="{{ url('search', $categories[$i]->id) }}" class="menuLinks leftCategoriesProduct"> <span class="catText">{{($categories[$i]->name)}}</span></a>
Hope this work for you !!!

<a style="cursor: pointer;" href="{{ url('search?category='.$categories[$i]->id)}}" class="menuLinks leftCategoriesProduct"> <span class="catText">{{($categories[$i]->name)}}</span></a>

Related

How to use <a> Tag to show children View on top of parent in Laravel blade?

I am new to Laravel and I have been trying to display partial children view on top of parent view using hyperlink. But nothing happens when I click on my hyperlink. on the other hand it is working on normal button.
Here is the code that works without any problem on normal button.
<button type="button" id="close_register" title="{{ __('cash_register.close_register') }}" class='button-custom' data-container=".close_register_modal"
data-href="{{ action('CashRegisterController#getCloseRegister')}}">
<!-- <strong><i class="fa fa-window-close fa-lg"></i></strong> -->
</button>
And here is the hyperlink based button code.
<a id="close_register" data-container=".close_register_modal"
data-href="{{ action('CashRegisterController#getCloseRegister')}}" class='glowBtn'>Day Close
</a>
Any help would be highly appreciated Thanks in advance.
Actually this is not a Laravel problem, but a simple HTML one. Your tag is missing an HREF attribute. Use javascript:void(0);, if you want to avoid reloading the page unexpectedly.
<a
id="close_register"
data-container=".close_register_modal"
data-href="{{ action('CashRegisterController#getCloseRegister')}}"
href="javascript:void(0);"
class='glowBtn'>Day Close
</a>

How to debug Laravel Blade file during rendering

I'm working on a Laravel 7 app that is using data it gets from an API. Sometimes part of the data from the API is missing and I try to catch that firstly in the controller, secondly in the Blade view. But I still get crashes during rendering of the Blade view, that I have trouble debugging. I suspect that the crash occurs during rendering of statements like this:
<div class="flex-none">
<img src="{{ $game['coverImage'] }}" alt="cover">
</div>
or like this:
#foreach($game['screenshots'] as $screenshot)
#if(isset($screenshot))
<div>
<a href="{{ $screenshot['huge'] }}">
<image src="{{ $screenshot['big']}}" alt="screenshot"
class="hover:opacity-75 transition ease-in-out duration-150"></image>
</a>
</div>
#endif
#endforeach
Is there a way to dump the values of the variable during rendering of the Blade file? Equivalent to dd() or dump().
Or are there better ways to debug these crashes?
Kind regards,
Hubert

Passing a user id in a url in laravel

I'm making a Laravel web application, in this application, I have an Account Settings page. On this page, I want to display all the orders the user has made. In order to do this, I have to get the User id from the URL.
I tried passing the User id thru the URL by putting the Auth::user()->id in the route that leads to the page. however, this is giving me a 404 not found error.
This is the link that should pass the ID in the URL.
<a class="dropdown-item" href="{{ route('account/{{ Auth::user()->id }}') }}">
{{ __('Account Settings') }}
</a>
I also tried to change my web.php file but that's also not giving any result.
I really would appreciate some help with my problem since I've been stuck on this all day.
You're using Laravel route helper. the route would work only for NAMED ROUTE,
for example:
Route::get('account/{userId}', 'AccountController#show')->name('account');
Then, your could should be:
<a class="dropdown-item" href="{{ route('account', ['userId' => Auth::id()]) }}">
{{ __('Account Settings') }}
</a>

How to create anchor tag in Laravel 5.1

I need help as I am trying to create anchor tag in Laravel 5.1
I used this line & this works
{!! Html::link('/dashboard','Dashboard') !!}
But I have code like this
<a href="#" class="logo">
<span class="logo-mini"><b>cpy</b></span>
<span class="logo-lg"><b>Company</b></span>
</a>
I want to fit above code into Laravel 5.1 link format , but i am unable to get it .
Someone help me to sort out this.
You can use URL or route to anchor element.
<a href="{{ URL::to('dashboard')}}" class="logo">
<span class="logo-mini"><b>cpy</b></span>
<span class="logo-lg"><b>Company</b></span>
</a>
This points to /dashboard. If you wish to suffix a parameter for example base-path/dashboard/user-name
then,
<a href="{{ URL::to('dashboard', $username)}}" class="logo">
<span class="logo-mini"><b>cpy</b></span>
<span class="logo-lg"><b>Company</b></span>
</a>
When using URL, makes sure the path is set in routes.php

Laravel 4.1 blade linking to user profile picture

I am trying to link to a user profile image in Laravels blade template but I am only getting errors here.
This is my image tag containing the link:
<img class="img-circle dashboardprofileimage" src="{{ URL::asset('img/profile_pictures/users/{{ Auth::user()->profile_picture }}') }}"/>
I would be very happy if anyone could help me out here. I guess its a simple thing but I have tried quite a lot of times now.
Thanks.
Your error is using nested {{ }}, you just need it once. Check out the correct code below:
<img
class="img-circle dashboardprofileimage"
src="{{
URL::asset('img/profile_pictures/users/' . Auth::user()->profile_picture)
}}" />
Note: it's splited into several lines for better legibility.
you just use {{ }} one time to print URL::asset() and Auth::user()
<img class="img-circle dashboardprofileimage" src="{{ URL::asset('img/profile_pictures/users/'.Auth::user()->profile_picture) }}"/>

Categories