Вопрос:

Accessing session variable inside css file laravel

php css laravel session laravel-5

221 просмотра

2 ответа

2802 Репутация автора

I have a css file name style-usercolors.css.php for dynamic css color in my laravel app. Inside the file I can declare variable and use it, but can't access the session variable.

header("Content-type: text/css");

$primaryColor = session()->has('ORGANISATION_SETTINGS') ? session()->get('ORGANISATION_SETTINGS')['style_settings']['primary_color'] : '#F18805';
$secondaryColor = session()->has('ORGANISATION_SETTINGS') ? session()->get('ORGANISATION_SETTINGS')['style_settings']['secondary_color'] : '#20576B';
$offwhite = '#f6f6f6';
Автор: hizbul25 Источник Размещён: 12.04.2017 08:53

Ответы (2)


0 плюса

204 Репутация автора

You need to have a defined route to access the session in Laravel. When you define routes in web.php, the StartSession Middleware is enabled by default. That starts the Laravel session.

These middlewares are defined in App\Http\Kernel.php, in the web section.

In other words, to use the session, you need to create a specific route for your css file, add: header("Content-Type: text/css"); to it and require your css there.

Finally, in your main view, you have to create a link to that page:

<link href="http://example.com/link-to-your-css-page/" rel="stylesheet" type="text/css"/>

( Notice how we don't have a file extension at the end of the href attribute )

Автор: Borislav Itskov Размещён: 12.04.2017 09:22

0 плюса

2802 Репутация автора

Решение

Finally i'v created a blade file and there I write css along with session variable then include blade file into layout header section. And this process solved my issue.

Автор: hizbul25 Размещён: 12.04.2017 10:29
Вопросы из категории :
32x32