Laravel Blade function -


in view in laravel app,i want display different background in each table cell.

imagine

<td>   switch($product->number)       @case('1')         "red"          @break;      [...]   @case('100')         "green"          @break;    @endswitch </td> 

so, have each cell in row wondering how call function inside view return color.

(i know faster on client side js, wondering).

how writing helper? can call in blade this:

{!!\app\library\tablehelper::colortext($product->number)!!} 

and in helper put under app/library:

<?php namespace app\library;   class tablehelper {     public static function colortext($text)     {         switch ($text)         {             case '1' : $text = '<span color="green"> ' . $text . '</span>'; break;             //...         }         return $text;     }     //to color:     public static function getcolor($text)     {         switch ($text)         {             case '1' : return 'green' ; break;             //...             default: return 'white';         }      } } 

Comments