vendredi 29 septembre 2017

How to handle front end dependencies paths in laravel?

I have a project in laravel, in which I want to use specific paths for resources (e.g: i have some resources in aws s3 and cloudfront), in the same way as asset() does. So i created a provider that loads the php helpers in specific folder with this code:

File: app/Providers/HelperServiceProvider.php:

<?php
namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class HelperServiceProvider extends ServiceProvider
{
    public function register()
    {
        // esto carga todo en Helpers!! use with caution :)
        foreach (glob(app_path() . '/Helpers/*.php') as $filename) {
            require_once $filename;
        }
    }
}

so i added it in providers array at config/app.php. Then I can define a function that is used in the templates to generate url to external paths:

<!DOCTYPE html>
<html>
    <head>
        <title>
            AppName - @lang('auth.title')
        </title>
        <link href="{!! my_asset('asset/in/S3.png') !!}" rel="stylesheet"/>
    </head>

I think this form is a bit out of the way things are done in laravel. Also I do not want to use preprocessors in js using node.js or laravel elixir to compile the assets and upload it to the cloud (and generate routes), because they add too much complexity to the project.

I wonder if there is a way more like laravel to handle the dependencies with external paths. Thanks



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2x2Nyc5
via IFTTT

Aucun commentaire:

Enregistrer un commentaire