How to access url for the current if statement of laravel

0 votes

I can access the url using php like <?php echo URL::current(); ?> but I guess it is not possile for @if blade statement.. so I wanted to access url through laravel?how can i do it?

Aug 7, 2020 in Laravel by subham
• 120 points

recategorized Aug 7, 2020 by Niroj 1,446 views

1 answer to this question.

0 votes

Hello @ subham ,

If you want to access the current url inside an @if statement in laravel  just use the below syntax:

@if(Request::url() === 'your url here')

    // code..............

@endif

Hope it helps!!
Thank you!

answered Aug 7, 2020 by Niroj
• 82,840 points
Hii niroj

Thank you for your response.

 I know this way we can access any blade objects url but how can we use those object to access in items containing list?

Hello @subham,

if you want to use url in list blade you can do something like this:

<li class="{{ Request::is('mycategory/', '*') ? 'active' : ''}}">
So can we use that in both unorder and ordered list as well?

Hello @ subham,

Yes,you can use in both unorder and ordered list as well. Alternate method you can use is:

<li{!!(Request::is('your_url')) ? ' class="active"' : '' !!}>

or

<li @if(Request::is('your_url'))class="active"@endif> 

Hope it helps!!
Thank you!!

Thanx man..u helped me a lot

Related Questions In Laravel

0 votes
1 answer

How to pass data through URL and access through controller in Laravel?

Hello, You can  first refer how to  Create controller through ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
11,965 views
0 votes
1 answer

How can I echo the version of the current Laravel version in php using the view?

Hello @kartik, This is the way how to ...READ MORE

answered Aug 10, 2020 in Laravel by Niroj
• 82,840 points
1,283 views
0 votes
1 answer

How to select year and month from the created_at attributes of database table in laravel 5.1?

Hello @kartik, There are date helpers available in ...READ MORE

answered Sep 30, 2020 in Laravel by Niroj
• 82,840 points
15,583 views
0 votes
1 answer

How to get all the users except current logged in user in laravel eloquent?

Hello @kartik, You can get the current user's ...READ MORE

answered Dec 8, 2020 in Laravel by Niroj
• 82,840 points
7,581 views
0 votes
0 answers

How to create custom pagination in JavaScript?

With the help of examples, can you ...READ MORE

Dec 19, 2024 in Java-Script by Ashutosh
• 12,620 points
42 views
0 votes
1 answer

Which one is better, Netlify or Vercel?

Both Netlify and Vercel are excellent for ...READ MORE

answered Dec 12, 2024 in Node-js by Navya
44 views
0 votes
1 answer

How do I clear the server cache in asp.net?

Clearing Data from Cache Object (Application Cache) If ...READ MORE

answered Dec 17, 2024 in PHP by Navya
63 views
0 votes
0 answers

How to handle cache busting in Angular?

With the help of a code example, ...READ MORE

Dec 19, 2024 in Angular by Ashutosh
• 12,620 points
34 views
0 votes
1 answer

How to Get the Current URL Inside @if Statement in Laravel?

Hello @kartik, You can use: Request::url() to obtain the current ...READ MORE

answered Nov 11, 2020 in Laravel by Niroj
• 82,840 points
4,073 views
0 votes
1 answer

How Can I Set the Default Value of a Timestamp Column to the Current Timestamp with Laravel Migrations?

Hello, To create both of the created_at and updated_at columns: $t->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP')); $t->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP on update ...READ MORE

answered Apr 2, 2020 in Laravel by Niroj
• 82,840 points
12,212 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP