Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to declare global variable in laravel controller

class TestController extends Controller
{
    private $x;

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

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

create global function laravel

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

global variable in laravel

//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')
Comment

create global function laravel

 //AppProvidersGlobalFunctionsServiceProvider.php

 public function register()
 {
     require_once base_path().'/app/Functions/GlobalFunctions.php';
 }
Comment

create global function laravel

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

create global function laravel

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

create global function laravel

 //AppConfigApp.php

 'providers' => [

     /*
     * Laravel Framework Service Providers...
     */
     IlluminateAuthAuthServiceProvider::class,
     ...
     IlluminateValidationValidationServiceProvider::class,
     IlluminateViewViewServiceProvider::class,
     AppProvidersGlobalFunctionsServiceProvider::class, //Add your service provider
Comment

create global function laravel

 //Use your function anywhere within your Laravel app
 first_function();
 second_function();
Comment

PREVIOUS NEXT
Code Example
Php :: example of valid php variables 
Php :: validate unique or equal 
Php :: how to remove public folder from url in laravel 8 
Php :: how to disable laravel cors 
Php :: laravel read csv 
Php :: Search Multiple columns using one input 
Php :: custom-taxonomy-image-option-in-admin-panel 
Php :: King Composer Theme Export 
Php :: requires ext-pcntl 
Php :: How to add watermark in FPDF PHP - Parte 1 
Php :: phplinit config 
Php :: convert any date to db date in suitecrm 
Php :: MForm Bild Attribute 
Php :: php if class exists 
Php :: php code inside html 
Php :: laravel pagination bootstrap sorting column 
Php :: WP Admin Bar Dev Links 
Php :: phpexcel rangetoarray date format 
Php :: cakephp3 form control plus traditional php form 
Php :: custom attributes get all custom fields 
Php :: Loading an image using a PHP script 
Php :: flask like framework for php 
Php :: PHP OOP - Interfaces 
Php :: Wordpress srcset with ACF Image & lazy Load 
Php :: ?id=$1&user=$2 
Php :: how we generate a single column migration in laravel 
Php :: Laravel API ResourceCollection doesnt works 
Php :: use htaccess to redirect in cpanel lsrsvel 
Php :: Drupal 9 loop term objects to retrieve term data (id, name, uuid) 
Php :: wordpress code 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =