ml-archive / nodes-php-backend

Nodes backend package
http://nodesagency.com
MIT License
11 stars 5 forks source link
admin-panel laravel nodes php

Backend

A easy and clean backend to Laravel.

Total downloads Monthly downloads Latest release Open issues License Star repository on GitHub Watch repository on GitHub Fork repository on GitHub StyleCI

πŸ“ Introduction

One thing we at Nodes have been missing in Laravel is a fast implemented backend which is easy to build on top of

πŸ“¦ Installation

To install this package you will need:

You must then modify your composer.json file and run composer update to include the latest version of the package in your project.

"require": {
    "nodes/backend": "3.1.*",
}

Or you can run the composer require command from your terminal.

composer require nodes/backend

πŸ”§ Setup

Setup service providers in config/app.php

Nodes\Backend\ServiceProvider::class,
Nodes\Assets\ServiceProvider::class,
Nodes\Validation\ServiceProvider::class,
Nodes\Cache\ServiceProvider::class,
Collective\Html\HtmlServiceProvider::class,
Nodes\ServiceProvider::class,

Setup alias in config/app.php

'Backend'        => Nodes\Backend\Support\Facades\Backend::class,
'Form'           => Collective\Html\FormFacade::class,
'Html'           => Collective\Html\HtmlFacade::class,

Publish config file all config files at once, we need to use force on backend, since we override gulp. The regular vendor:publish is for the 3 other packages

php artisan vendor:publish && php artisan vendor:publish --provider="Nodes\Backend\ServiceProvider" --force

Publish config file for backend plugin only

php artisan vendor:publish --provider="Nodes\Backend\ServiceProvider"

Overwrite config file for backend plugin only

php artisan vendor:publish --provider="Nodes\Backend\ServiceProvider" --force

Add following to your /database/seeds/DatabaseSeeder.php

$this->call('NodesBackendSeeder');

Dump

composer dump-autoload

Now you can call php artisan migrate --seed Which will add the new tables and seed the roles/users to get going

Add to config/nodes/autoload.php

'project/Routes/Backend/',

Run bower, npm & gulp to build css & js

bower install && npm install && gulp build

Set up CSRF by pass in App\Http\Middleware\VerifyCsrfToken.php

protected $except = [
    'admin/manager_auth',
];

Make TokenMismatch exceptions more user friendly, add following to App\Exceptions\Handler.php

public function render($request, Exception $e)
{
    // Just redirect back to previous route if there is any, else all the way back to dashboard
    // Instead of a ugly whoops error!
    if ($exception instanceof TokenMismatchException) {
        try {
            return redirect()->back()->with('error', 'Token mismatch, try again')->send();
        } catch (\Throwable $e) {}
    }
    ....
}

βš™ Usage

Global function

backend_auth - Access all other function on mananger
backend_user - Retrieve user object
backend_user_check - Check if there is authed user
backend_user_authenticate - Try to auth with current request, pass [] as providers are registered
backend_user_login - Force login another user
backend_user_logout - Logout user
backend_attempt - Attempt to authenticate a user using the given credentials
query_restorer - Use to restore query params from cookie, handy for routing between views with queries
query_restorer_with_flash - Use to restore query params from cookie, handy for routing between views with queries. Remembers the flash between reloads also
backend_router - Access all other router functions
backend_router_pattern - Used fx for selecting navigation item by path 
backend_router_alias - Used fx for selecting navigation item by route

Redirect with flash

redirect()->back()->withInput()->with('error', 'Unknown Error') // Only strings
redirect()->back()->withInput()->with('errors', $myErrorBag)
redirect()->back()->withInput()->with('errors', $myValidator->errorsBag());
redirect()->back()->withInput()->with('success', 'Everything is ok')
redirect()->back()->withInput()->with('info', 'Insert info')
redirect()->back()->withInput()->with('warning', 'Insert warning')

πŸ† Credits

This package is developed and maintained by the PHP team at Nodes

Follow Nodes PHP on Twitter Tweet Nodes PHP

πŸ“„ License

This package is open-sourced software licensed under the MIT license