class TestController extends Controller
{
private $x;
public function index()
{
$this->x ='22';
}
public function send_message()
{
echo $this->x;
}
}
//Into the console
php artisan clear-compiled
php artisan config:cache
//create globals.php file in laravel/config/ and add the ff:
<?php
return [
'user_type' => [
'administrator' => 1,
'hr' => 2,
'employee' => 3
]
];
//then you can call it in your controllers or blade using
config('globals.user_type.employee')
//AppProvidersGlobalFunctionsServiceProvider.php
public function register()
{
require_once base_path().'/app/Functions/GlobalFunctions.php';
}
Composer //Autload whitin composer.json method
|
|--->Laravel App //My method
|
|--->Controller //Trait method
|--->Blade //Trait method
|--->Listener //Trait method
|--->...
//Into the console
php artisan make:provider GlobalFunctionsServiceProvider
//AppConfigApp.php
'providers' => [
/*
* Laravel Framework Service Providers...
*/
IlluminateAuthAuthServiceProvider::class,
...
IlluminateValidationValidationServiceProvider::class,
IlluminateViewViewServiceProvider::class,
AppProvidersGlobalFunctionsServiceProvider::class, //Add your service provider
//Use your function anywhere within your Laravel app
first_function();
second_function();