Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ramher101's avatar

Fetching Session.. blade or controller

whats the most efficient way of handling session variables

blade file

$('#applicant-monthly-salary').val('{{Session::get("credit-investigation.".$id.".disposable-income.applicant-monthly-salary")}}');

controller file

$DI_monthly_salary_applicant    = Session::get("credit-investigation.".$id.".disposable-income.applicant-monthly-salary");

in controller i return it in compact and access the variable in the blade file like

{{$DI_monthly_salary_applicant}}

any differences? opinions?

PS Im having problems with session sometimes its inconsistent when I refresh the page

0 likes
1 reply
bobbybouwmann's avatar

It doesn't really matter, but I prefer to do this in the controller. Make your views dumb and only work with variables they get from the controller. If you add a session now you might add other stuff later or more sessions and your views get bloated and unreadable. That's my 2 cents.

Please or to participate in this conversation.