0

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?

3 Answers 3

2

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

@php
    $var = \App\Helper::call();
@endphp
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

try to clear caches

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.