I would like to create helper functions to avoid repeating code between views in Laravel 5:
view.blade.php
Foo Formated text: {{ fo
**
** create new helper
[
'value' => 1,
'displayName' => 'Active',
],
2 => [
'value' => 2,
'displayName' => 'Inactive',
],
3 => [
'value' => 3,
'displayName' => 'Delete',
],
];
public static function getStatusesList()
{
$status = (new Collection(self::$_status))->pluck('displayName', 'value')->toArray();
return $status;
}
}
Use for the controller and any view file
use App\Helpers\StatusHelper;
class ExampleController extends Controller
{
public function index()
{
$statusList = StatusHelper::getStatusesList();
return view('example.index', compact('statusList'));
}
}