GEOFFREY MWANGI GEOFFREY MWANGI - 1 year ago 196
PHP Question

Laravel blade assign css class conditionally

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

Answer Source

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>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download