KbZuhn
KbZuhn

Reputation: 57

Laravel loading helper not automatically

I tried to load my helper without composer autoload

For controllers I use:

use \App\Helper;

Works good, But for blade's view how can I load it?

Upvotes: 0

Views: 283

Answers (3)

ThataL
ThataL

Reputation: 165

in blade view you can use as \App\Helper::call();

@php
    $var = \App\Helper::call();
@endphp

Upvotes: 2

Davit Zeynalyan
Davit Zeynalyan

Reputation: 8618

You can do it 2 ways

Solution 1: make aliases

In config\app.php change aliases to

'aliases' => [
    'App' => Illuminate\Support\Facades\App::class,
    'Artisan' => Illuminate\Support\Facades\Artisan::class,
    'Auth' => Illuminate\Support\Facades\Auth::class,
    ...................
    'Helper' => App\Helper::class,
]

in blade use

@php
    $result = Helper::staticFunction();
    // or
    $helper = app(Helper::class);
    $helper->functionName(); 
@endphp

Solution 2:

@php
    $result = \App\Helper::staticFunction();
    // ot
    $helper = app(\App\Helper::class);
    $helper->functionName();
@endphp

Upvotes: 1

Ahmed Atoui
Ahmed Atoui

Reputation: 1556

try to clear caches

php artisan cache:clear php artisan config:clear php artisan route:clear

Upvotes: 0

Related Questions