Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i include php file from blade in laravel

Hello Guys In Laravel Blade I Want To Include Php file i try to use @include but it doesn’t work because @include to include views not php file

My File I Want To Include

App\Helpers\Variables.php

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$dufaultLang = get_dufault_lang();
$categories =
    mainCategory::where(
        'translation_lang',

        $dufaultLang
    )
        -> Selection()  // Select From Selection Scope
        -> get();       // Get Selection Data

MyBlade

<ul class="menu level1">

@include('App.Helpers.Variables.php') // Here It Doesn't Work

@if(isset($categories) && $categories -> count() > 0)

@foreach($categories as $category)
Hello
@endforeach

@endif

</ul>

I Can’t Include The $Categories From Variables.php I Try To Use @include but I see This Error

View [App.Helpers.Variables.php] not found.

>Solution :

use Sharing Data With All Views

In AppServiceProvider boot method

public function boot()
{
  $dufaultLang = get_dufault_lang();
  $categories =mainCategory::where('translation_lang', $dufaultLang)
                -> Selection()  
                -> get();       
  View::share('categories', $categories);
}

and in your view

<ul class="menu level1">
    @if(isset($categories) && $categories->count() > 0)

        @foreach($categories as $category)
            Hello
        @endforeach
    @endif

</ul>

Also, make sure follow to the naming convention for the model class

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading