are looking for helper classes? http://laravel.io/forum/02-03-2015-best-practices-for-custom-helpers-on-laravel-5?page=1
Your question is look like Best practices for custom helpers on Laravel 5. No worries..! let check in brief.
I think you requesting for helper function. You can place you php function body at single file and you can use this through the site. Let's we check it step by step:
1) Create Helper.php to wrap your helper(PHP) function(s) under app/Helpers/. So your Helper.php code like:
namespace App\Helpers;
class Helper
{
public static function hello()
{
return "Hello..!";
}
}
2) Add alias in config/app.php
'aliases' => [
.
.
'Helper' => 'App\Helpers\Helper::class',
],
3) Use helper function hello() in blade file:
{!! Helper::hello() !!}{{--This will print 'hello' from hello() helper method}}
4) You can use helper function into controller like:
namespace App\Http\Controllers;
use App\Helpers\Helper;
class MyController extends Controller
{
public function __construct()
{
Helper::hello();
}
}
You can get more idea from stack answer Best practices for custom helpers on Laravel 5 taken help from same.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community