PHP code example of morningtrain / laravel-context

1. Go to this page and download the library: Download morningtrain/laravel-context 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/ */

    

morningtrain / laravel-context example snippets




namespace App\Providers;

use App\Context\BaseContext;
use App\Context\App\AppContext;
use MorningTrain\Laravel\Context\ContextServiceProvider as ServiceProvider;
use MorningTrain\Laravel\Context\Plugins\Assets\AssetsPlugin;
use MorningTrain\Laravel\Context\Plugins\Env\EnvPlugin;
use MorningTrain\Laravel\Context\Plugins\Menus\MenusPlugin;
use MorningTrain\Laravel\Context\Plugins\Meta\MetaPlugin;
use MorningTrain\Laravel\Context\Plugins\Routes\RoutesPlugin;

class ContextServiceProvider extends ServiceProvider
{

    /**
     * Plugins to load
     *
     * @var array
     */
    protected $plugins = [
        AssetsPlugin::class,
        EnvPlugin::class,
        MenusPlugin::class,
        RoutesPlugin::class,
        MetaPlugin::class
    ];

    /**
     * Features to define
     *
     * @var array
     */
    protected $contexts = [
        'base'  => BaseContext::class,
        'app'   => AppContext::class,
    ];

    /**
     * Features to load
     *
     * @var array
     */
    protected $load = [
        'base'
    ];

}



namespace App\Context\App;

use MorningTrain\Laravel\Context\Context;

class AppContext
{

    public function load()
    {
        // Provide the app name to ENV
        Context::env(function () {
            return [
                'app' => [
                    'name' => config('app.name')
                ]
            ];
        });

        // Load assets
        Context::load(Assets::class);

    }

}




namespace App\Context\App;

use MorningTrain\Laravel\Context\Context;

class Assets
{

    protected $manifest = '';

    public function load()
    {
        Context::stylesheets([
            asset(mix('css/app.css', $this->manifest))
        ]);

        Context::scripts([
            asset(mix('js/manifest.js', $this->manifest)),
            asset(mix('js/vendor.js', $this->manifest)),
            asset(mix('js/app.js', $this->manifest))
        ]);
    }

}



namespace App\Context\App;

use MorningTrain\Laravel\Context\ContextProvider;

class AppContext extends ContextProvider
{

    protected $partials = [
        Assets::class,
    ];

}




namespace App\Context\App;

use MorningTrain\Laravel\Context\Context;
use MorningTrain\Laravel\Context\ContextProvider;
use MorningTrain\Laravel\Context\Plugins\Assets\AssetsPlugin;

class Assets extends ContextProvider
{

    public static $plugins = [
        AssetsPlugin::class
    ];
    
    protected $manifest = '';

    public function load()
    {
        Context::stylesheets([
            asset(mix('css/app.css', $this->manifest))
        ]);

        Context::scripts([
            asset(mix('js/manifest.js', $this->manifest)),
            asset(mix('js/vendor.js', $this->manifest)),
            asset(mix('js/app.js', $this->manifest))
        ]);
    }

}