after getting last url segment i am creating a class active.
last segment id i have in :
#php$get=Request::segment(3);#endphp
<a href="{{BASE}}User/li-ac">
<div class="col-md-12">
<div class="col-md-12 {{ collect(request()->segments())->last()=='li-ac' || collect(request()->segments())->last()=='li-de' ? 'Active' : '' }}">
</div>
</div>
</a>
i want to add this $get after
collect(request()->segments())->last()=='li-de' in if condition to get
my Active class.
when Url Is:
mysite.com/user/li-ac
Its working fine
But Url is:
mysite.com/User/li-de/3
Its not showing that class
how can i add the id at the end of the url in if condition for
sideactive class..
When you're using /newdata/li-de/3 URI, the last segment is 3. So, change the code to:
{{ in_array(request()->segments()[1], ['li-ac', 'li-de']) ? 'sideactive' : '' }}
I am done here is the answer:
#php
$get=Request::segment(2);
#endphp
{{ collect(request()->segments())->last()=='li-de' || $get=='li-de' ? 'active' : '' }}
Related
With laravel 8.68 and livewire 2.7 opening modal dialog (which can be used in many cases) I want
to change background color/color depending on parameter.
I try to change class in <x-jet-dialog-modal definition like :
<x-jet-dialog-modal wire:model="confirmActionModalProfileFormVisible"
class=" z-50 bg-opacity-100 #if($confirm_action_profile_modal_color === 'danger') personal_danger_text #else personal_text #endif">
But That does not work, and in browser's inspection I see that class in <x-jet-dialog-modal is not rendered,
I try to use alpinejs :
<x-jet-dialog-modal wire:model="confirmActionModalProfileFormVisible"
:class=" 'z-50 bg-opacity-100 ' + ( '{{$confirm_action_profile_modal_color }}' == 'danger' ? 'personal_danger_text' : 'personal_text' ) ">
But error was raised :
A non-numeric value encountered (View: my-template.blade.php)
Can I make condition for class of <x-jet-dialog-modal ?
UPDATED # 1:
Yes, I have jetstream views published , and I have file resources/views/vendor/jetstream/components/dialog-modal.blade.php,
which have default content :
#props(['id' => null, 'maxWidth' => null, 'class' => null])
<x-jet-modal :id="$id" :maxWidth="$maxWidth" {{ $attributes }} class="{{ !empty($class) ? $class : ''}}">
<div class="px-6 py-4 {{ !empty($class) ? $class : ''}}">
<div class="text-lg">
{{ $title }}
</div>
<div class="mt-4">
{{ $content }}
</div>
</div>
<div class="px-6 py-4 text-right {{ !empty($class) ? $class : ' bg-gray-100'}}">
{{ $footer }}
</div>
</x-jet-modal>
As I inheret my modal file from it I wonder in which way have I to edit definition of <x-jet-dialog-modal to pass
conditional class ?
Thanks in advance!
you have to publish jetstream views, then edit the file dialog-modal.blade.php and use the slot attributes.
Laravel Blade #Slot Attributes
If you want to change something from the modal itself, you would have to edit modal.blade.php
Edit the following line:
<div x-show="show" class="mb-6 bg-white rounded-lg overflow-hidden shadow-xl transform transition-all sm:w-full {{ $maxWidth }} sm:mx-auto">
And do attribute merge Laravel Blade #Deafault/Merged Attributes
another way will be to edit published JetStream modal window view (resources/views/vendor/jetstream/componets/modal.blade.php) and add {{$attributes['class']}} in class values. After that you can add any custom class or condition when including jetstream modal:
<x-jet-dialog-modal wire:model="myCustomModal" maxWidth="md" class="flex items-center my-custom-class">
and this will be applied on your modal. And now you should be able to use your conditions as well:
<x-jet-dialog-modal wire:model="myCustomModal" maxWidth="md" class="flex items-center my-custom-class #if($confirm_action_profile_modal_color === 'danger') personal_danger_text #else personal_text #endif">
nice example can be seen here:
https://floyk.com/en/post/how-to-use-laravel-jetstream-livewire-modal
or here:
https://floyk.com/en/post/livewire-5-ways-to-call-and-update-value-on-click
I have faced a typical problem. The problem is which controller data object being executed in view page. Here the data object is $items. I have looked most of controller but can not find data object $items . Please help me to find it. Thank in advance. The portion of view page :
#foreach($items as $item)
<div class="partner-logo">
<div class="inner-div red-box">
<p>
<img src="{{ ($item->image) ? asset('file/images/' . $item->image) : "" }}" alt="" />
</p>
<h3>
<a
href="{{ isset($item->url) ?route('page.content.show', $item->url) : "#" }}"> {{ $item->title }}
</a>
</h3>
</div>
</div>
#endforeach
In Laravel, controllers usually pass their data to views in this format:
return view('nameOfView', [
'firstParam' => $firstParam,
'secondParam' => $secondParam,
'etc' => $etc
]);
So you can search in your controllers for the view name and then for the parameter name (in this case $items). If there are multiple controller functions with the $items param and the same view, add a test param to each and see which one your view renders. You can also check in routes/web.php for the current URL you are on, and find the correct controller function that way.
Can somebody explain me difeerence between
Request::is()
and
Request::patch()
??
I used request::is in my code to active navbar like this, but i saw that somebody use too request::patch
<div class="nav-collapse">
<ul class="nav">
<li class="{{ Request::is('/') ? 'active' : ''}}"><a href="/">#
</a</li>
#foreach($categories as $category)
<li class="{{ Request::is($category->name) ? 'active' : '' }}">
{{$category->name}}</li>
#endforeach
</ul>
</div>
In Side patch Request :
patch request says . only send the data which one you want to update
and it won't effecting or changing other data . so no need to send all
value again . just i want to update my first name so i need to send
only first name to update .
In Side Is Request :
https://indigotree.co.uk/laravel-4-using-request-is-named-routes/
Laravel 4.1 Request::is for active menu not working
Example
<li
{{{ (Request::is('/core') ? 'class=active' : '') }}}>Control Panel
</li>
and Check 'class="active"' to 'class=active'
This working fine for <li> tag but not <a> tag, needs to be used like so:
Overview
I get link something like this : http://local.dev/blog/articles/2/Category12
#foreach($categories as $category)
<li>{{$category->title}} ({{ $category->count }})</li>
#endforeach
What i want is to set active class on li for category that im on. Any suggestion? Maybe i need to compare id from url and this in foreach. But how?
You can get ID of a category from URI with request()->segment(3):
<li {{ request()->segment(3) == $category->id ? 'class="active"' : '' }}>
yeild() in the <li> section as css class with a name and active it from the view layout. Like
<li class="#yield('mymenu')">
<a href="/blog/articles/{{$category->id}}/{{$category->slug}}">{{$category>title}} ({{ $category->count }})
</a>
</li>
In the view file
#section('mymenu', 'active')
So when you'll click on the link it will generate a class which name mymenu and when it will load to a view file then it will be active.
I am new to Laravel and don't know if it is possible at all to concatenate a string to a blade variable.
I want to display the name of the author with the ~ sign concatenated to the author's name from the left. Here is my code.
<div class="author">~{{ $quote->author or '' }}</div>
What I want is if the author is set, it should be displayed with the ~.
How do I concatenate this?
Thanks for any help
This would be better
<div class="author">~{{ isset($quote->author) ? $quote->author : '' }}</div>
UPDATE:
<div class="author">{{ isset($quote->author) ? '~'.$quote->author : '' }}</div>
<div class="author">
#if (isset($quote->author))
~ {{ $quote->author }}
#else
#endif
</div>
https://laravel.com/docs/5.3/blade#control-structures