simonmarcellinden/scriptloader 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

simonmarcellinden/scriptloader

Composer 安装命令:

composer require simonmarcellinden/scriptloader

包简介

Package for load dynamically Scripts & Styles

README 文档

README

Latest Version on Packagist Total Downloads Build Status

With this package you can manage header Styles and Scripts Tags to load from Laravel controllers.

Installation

From the command line run

$ composer require simonmarcellinden/scriptloader

Laravel <= 5.4

Once ScriptLoader is installed you need to register the service provider with the application. Open up config/app.php and find the providers key.

Add the service provider to config/app.php

    SimonMarcelLinden\ScriptLoader\ScriptLoaderServiceProvider::class,

Optionally include the Facade in config/app.php if you'd like.

    "ScriptLoader" =>"SimonMarcelLinden\ScriptLoader\Facades\ScriptLoader::class,

Publish the configurations

Run this on the command line from the root of your project:

$ no config needed

A configuration file will be publish to config/scriptloader.php.

Usage

Examples

Add a Script or Style Source directly into your route or controller

app/Http/Controllers/Controller.php

<?php 

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesCommands;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;

use ScriptLoader;

abstract class Controller extends BaseController  {
    use DispatchesCommands, ValidatesRequests;

    public function __construct() {
        // Defaults
        ScriptLoader::set("style", asset('css/default.css'), 3);
        ScriptLoader::set("style", asset('css/app.css'), 1);
    }
}

app/Http/Controllers/HomeController.php

<?php 

namespace App\Http\Controllers;

use ScriptLoader;

class HomeController extends Controller  {
    public function index() {
        // Section description
        ScriptLoader::set("style", asset('css/home.css'), 2);
        ScriptLoader::set("script", asset('js/home.js'), 4, "defer");

        return view('index');
    }

    public function detail() {
        // Section description
        ScriptLoader::set("style", asset('css/details.css'), 2);
        ScriptLoader::set("script", asset('js/details.js'), 2);

        return view('detail');
    }

    public function privateProfile() {
        ScriptLoader::set("style", asset('css/home.css'), 2);
        ScriptLoader::set("style", asset('css/private.css'), 3);
        ScriptLoader::set("script", asset('js/private.js'), 4, "defer");

        return view('private');
    }
}

resources/views/layouts/app.blade.php

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="content-type" content="text/html; charset=utf-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <title>Laravel - ScriptLoader</title>

        {!! ScriptLoader::load() !!}
    </head>

    <body>
        @yield('content')
    </body>
</html>

Change log

Please see the changelog for more information on what has changed recently.

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email info@snerve.de instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固