1

I want to use Laravel config file values in my .css file to customize some colors how can I do this? or maybe it is impossible. I hope my question is clear Thank you.

my config file

return [
'custom' => [
    'mainLayoutType' => 'horizontal',
    'theme' => 'light',
    'sidebarCollapsed' => false,
    'navbarColor' => '',
    'navbarTextColor' => '#ffffff',
],

];

my css

.header-navbar .navbar-container ul.nav li > a.nav-link {
  color: #ffffff;
  padding: 1.6rem 1rem 1.35rem 0.5rem;
}

what I want to do is something like this

.header-navbar .navbar-container ul.nav li > a.nav-link {
  color: config('custom.navbarTextColor');
  padding: 1.6rem 1rem 1.35rem 0.5rem;
}

2 Answers 2

1

You cant add it in a CSS file or even a SCSS file. it has to be a PHP one.

There are two solutions that come to mind

The easy one is to add your css from config in a <style> tag in your blade file.

The hard way, is to return a css file via a route (/style.css). something like:

blade file (css.blade.php)

.header-navbar .navbar-container ul.nav li > a.nav-link {
    color: {{config('custom.navbarTextColor')}};
    padding: 1.6rem 1rem 1.35rem 0.5rem;
}

Route line

Route::get('/style.css', function() {
    return View::response('css')->header('Content-Type', 'text/css');
});
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the help, I used the first solution @N69D
1

You can dynamically add class to your root html element via php, then write styles in your css according to that.

Example:

<body>
  <main class="{{ config('theme') }}">
     ...
  </main>
</body>

1 Comment

Thanks @Mario for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.