“Como declarar variável global no controlador de Laravel” Respostas de código

Laravel use variável global no modelo

SET configuration variables at runtime:
class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        View::share('key', 'value');
        Schema::defaultStringLength(191);
        $company=DB::table('company')->where('id',1)->first();
        config(['yourconfig.company' => $company]);
    }
}

USE:
config('yourconfig.company');
Alemhar

Variável global no controlador Laravel

private $variable;
Fine Flatworm

Como declarar variável global no controlador de Laravel

class TestController extends Controller
{
    private $x;

    public function index()
    {
        $this->x ='22';
    }

    public function send_message()
    {
        echo $this->x;
    }
}
Funky Dev

Crie função global Laravel

 //Into the console
 php artisan clear-compiled
 php artisan config:cache
Ben10

Crie função global Laravel

Composer //Autload whitin composer.json method
|
|--->Laravel App //My method
     |
     |--->Controller //Trait method
     |--->Blade //Trait method
     |--->Listener //Trait method
     |--->...
Ben10

Crie função global Laravel

 //Into the console
 php artisan make:provider GlobalFunctionsServiceProvider
Ben10

Respostas semelhantes a “Como declarar variável global no controlador de Laravel”

Perguntas semelhantes a “Como declarar variável global no controlador de Laravel”

Mais respostas relacionadas para “Como declarar variável global no controlador de Laravel” em PHP

Procure respostas de código populares por idioma

Procurar outros idiomas de código