PHP code example of simonmarcellinden / scriptloader

1. Go to this page and download the library: Download simonmarcellinden/scriptloader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

simonmarcellinden / scriptloader example snippets


    SimonMarcelLinden\ScriptLoader\ScriptLoaderServiceProvider::class,

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

 

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);
    }
}

 

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');
    }
}

<!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>