nodes/backend

此软件包已被放弃,不再维护。未建议替代软件包。

Nodes后端软件包

3.2.7 2020-04-08 14:38 UTC

This package is auto-updated.

Last update: 2024-05-17 19:26:05 UTC


README

一个简单、干净的后端,适用于Laravel

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

📝 简介

我们团队在Laravel中缺少一个快速实现且易于构建的后端。

📦 安装

安装此软件包需要

  • Laravel 5.1+
  • PHP 5.5.9+

然后您必须修改您的 composer.json 文件并运行 composer update 以将软件包的最新版本包含到您的项目中。

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

或者您可以从终端运行 composer require 命令。

composer require nodes/backend

🔧 配置

在 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,

在 config/app.php 中配置别名

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

一次性发布所有配置文件,由于我们覆盖了gulp,我们需要在backend上使用强制,常规的 vendor:publish 仅适用于其他3个软件包

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

仅发布后端插件配置文件

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

仅覆盖后端插件配置文件

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

将以下内容添加到您的 /database/seeds/DatabaseSeeder.php 中

$this->call('NodesBackendSeeder');

转储

composer dump-autoload

现在您可以运行 php artisan migrate --seed,这将添加新的表并初始化角色/用户以开始使用

添加到 config/nodes/autoload.php

'project/Routes/Backend/',

运行 bower,npm & gulp 以构建 css & js

bower install && npm install && gulp build

通过在 App\Http\Middleware\VerifyCsrfToken.php 中传递来设置 CSRF

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

使 TokenMismatch 异常更友好,将以下内容添加到 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) {}
    }
    ....
}

⚙ 使用

全局函数

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()->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')

🏆 致谢

此软件包由Nodes的PHP团队开发和维护

Follow Nodes PHP on Twitter Tweet Nodes PHP

📄 许可证

此软件包是开源软件,根据MIT许可证许可