How to use static function in tempate blade.php in laravel 4?

I have an open public class method that captures some database information and returns an integer. In the controller, I can call this method just fine. How to call this static method in a click template?

For instance:

@foreach ($tasks as $task) {{Task::percentComplete($task->id)}}%<br /> @endforeach 

thanks

+6
source share
2 answers

You can either

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

B- Move it to assistant / library: fooobar.com/questions/405846 / ...

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

+6
source

One hacker way to do this is to simply embed PHP in your clip template, at least in Laravel 4.0; I migrated an old poorly written project to laravel. Having been so overwhelmed by the amount of problems I encountered and the time constraints, I did not have time to find the best way to do this. I made a bunch of html forms for a total of about 30 thousand lines of code.

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

Then you can normally access your data:

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

What worked for me.

NOTE. Just add your 2 cents for documentation. There are better and cleaner ways to do this, as the accepted answer says.

0
source

Source: https://habr.com/ru/post/947050/


All Articles