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 263 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,820 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,820 points
7,767 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,820 points
370 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,820 points
3,130 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,820 points
1,252 views
0 votes
1 answer

How to exclude specific folders every time I run 'eb deploy' using AWS EB CLI

If there is not .ebignore file it ...READ MORE

answered Oct 24, 2018 in AWS by Priyaj
• 58,140 points
1,077 views
0 votes
1 answer

Open-Source Forum with API

phpBB would be the first that comes ...READ MORE

answered Mar 5, 2019 in Python by SDeb
• 13,290 points
135 views
0 votes
0 answers

Self Created Laravel Link Not Working

I installed laravel 6.0 through composer and ...READ MORE

Dec 3, 2019 in Others by anonymous
• 120 points
157 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,820 points
621 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,820 points
7,592 views