How do I use a static function in blade.php tempate in laravel 4? How do I use a static function in blade.php tempate in laravel 4? laravel laravel

How do I use a static function in blade.php tempate in laravel 4?


You could either

A- Make it a Facade : http://laravel.com/docs/facades

B- Move it into a helper/library : https://stackoverflow.com/a/13481218/2446119

I personally think that helpers and libraries are much easier and quicker to code, but facades are cleaner.


One hackish way to do it is just embedding PHP in your blade template, at least in Laravel 4.0; I migrated an old project, poorly written, to laravel. Being so overwhelmed by the number of issues I ran into and time constraints I did not have time to look for a better way to do it. I did a bunch of html forms totaling about 30k lines of code.

<?php $haystack=Session::get('orderInfo.form.conditions',array());?>

Then you can access your data normally:

{{in_array('Special Assignments',$haystack)?'checked="checked"':''}}

That's what worked for me.

NOTE: Just adding my 2 cents for the sake of documentation. There are better and cleaner ways to do it, as stated by the accepted answer.