best practices

Functions w/o Class

Within your

  1. app/Http directory, create helpers.php file and add your functions:
    function ($x, $y){
        //return blah blah;
    }
    
  2. Within composer.json in the autoload block, add "files": ["app/Http/helpers.php"]
  3. Run composer dump-autoload in the terminal

With Class

in app/Providers/AppServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
        require_once __DIR__ . '/../Http/helpers.php';
    }
}

results matching ""

    No results matching ""