Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel blade assign css class conditionally

Tags:

php

laravel

I would like to add a css class condionally in my blade body tag by adding auth-container class if url is either /login or /auth/reset-password

so i have

<body> //here add class

So i have tried

@if(in_array(  , ['login','/auth/reset-password']) )//stuck here
   <body class="auth-container">
@else()
    <body> //no class
@endif()

Am stuck on how to figure out if the url is /login or /auth/reset-password hence add the class auth-container

like image 435
Geoff Avatar asked Nov 05 '25 21:11

Geoff


1 Answers

The is method in your request can check if the url is matching a pattern. You may use the * character as a wildcard:

<body @if(Request::is('login/*') || Request::is('auth/reset-password')) class="auth-container" @endif>
like image 149
Unamata Sanatarai Avatar answered Nov 07 '25 11:11

Unamata Sanatarai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!