create global function laravel

115

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
 //App\Config\App.php

 'providers' => [

     /*
     * Laravel Framework Service Providers...
     */
     Illuminate\Auth\AuthServiceProvider::class,
     ...
     Illuminate\Validation\ValidationServiceProvider::class,
     Illuminate\View\ViewServiceProvider::class,
     App\Providers\GlobalFunctionsServiceProvider::class, //Add your service provider
 //Into the console
 php artisan make:provider GlobalFunctionsServiceProvider
Composer //Autload whitin composer.json method
|
|--->Laravel App //My method
     |
     |--->Controller //Trait method
     |--->Blade //Trait method
     |--->Listener //Trait method
     |--->...

Comments

Submit
0 Comments