Including PHP files with Laravel framework

后端 未结 2 1937
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 12:23

I am trying to \"include\" a php script into one of my views (landing.blade.php).

The script is in:

/laravel-master/public/assets/scripts/config.p         


        
相关标签:
2条回答
  • 2020-12-24 13:10

    You can use includes in HTML forget about concatenation

    @include('foldername.filename')
    
    @include('filename')
    
    0 讨论(0)
  • 2020-12-24 13:21

    First, it's not really recommended that you keep your PHP files in the public directory, they should be kept inside the app folder. I'd suggest you create a folder inside app, something like includes and put your files there. Then, you include it, do:

    include(app_path().'/includes/config.php');
    

    Although, since it looks like you're trying to load some configuration files, I'd recommend you also check out Laravel's own way of handling configurations. For instance, if you created a myapp.php file inside the app/config folder, Laravel would handle it automatically for you, as long as you'd have some key-value pairs, like this:

    <?php
    
    return [
        'name'     => 'Raphael',
        'gorgeous' => true
    ];
    

    You could then retrieve these values using the Config class:

    Config::get('myapp.name'); // Raphael
    

    This is a better solution because you can also take advantage of Laravel's environment configuration.

    0 讨论(0)
提交回复
热议问题