heiw/uxcrudible

创建、读取、更新、删除接口,重点关注可用性和对关系的全面支持。

1.3 2021-06-22 13:31 UTC

This package is auto-updated.

Last update: 2024-09-21 18:13:12 UTC


README

HEIW应用程序的核心功能。包括

  • 用户
  • 角色
  • ...

文档

更多文档可以在 uxcrudible/docs/ 文件夹中找到。

安装

安装laravel

按正常方式安装 Laravel 8。

composer create-project --prefer-dist laravel/laravel blog

配置数据库连接

.env 中编辑您的连接设置

添加默认认证

在终端中运行以下命令

composer require laravel/ui
php artisan ui vue --auth
npm install
npm run dev

如果您遇到错误 Error: Cannot find module 'webpack/lib/rules/DescriptionDataMatcherRulePlugin',请运行 npm i vue-loader 然后重新运行 npm run dev

创建配置文件

在配置中创建一个名为 uxcrud.php 的配置文件

<?php

return [
    /**
     * The colour of the theme.
     */
    'theme_colour' => 'blue',

    /**
     * Controller namespace
     * Uxcrud will automatically look for a model's matching controllers in the
     * sub-folder specified.
     * This can be altered to your preference, it will need a trailing slash
     * e.g. 'Uxcrud\\'
     */
    'controller_namespace' => 'Uxcrud\\',

    /**
     * Model namespace
     * Uxcrud will automatically look for a controler's matching model in the
     * sub-folder specified.
     * This can be altered to your preference, it will need a trailing slash
     * e.g. 'Models\\'
     */
    'model_namespace' => 'Models\\',

    /**
     * Policy namespace
     * Uxcrud will automatically look for the policy in the sub-folder specified.
     * This can be altered to your preference, it will need a trailing slash
     * e.g. 'Policies\\'
     */
    'policy_namespace' => 'Policies\\',

    /**
     * Number of items per page to load for remote data for filters.
     */
    'remote_data_page_length' => 25,

    /**
     * Application Locale Configuration
     * The available locales that will be provided.
     * The fallback locale is the first locale listed.
     * locale code
     *      name    Localised name
     *      icon    Flag icon
     *      host    Host for locale
     */
    'locales' => [
        'en' => [
            'name' => 'English',
            'icon' => 'flag-icon-gb',
            'host' => env('HOST_EN')
        ],
        'cy' => [
            'name' => 'Cymraeg',
            'icon' => 'flag-icon-wales',
            'host' => env('HOST_CY')
        ]
    ],

    /**
     * Number of seconds after which to show the session timeout dialog.
     */
    'session_timeout_dialog' => 30 * 60, //env('SESSION_LIFETIME') * .8 * 60,

    /**
     * Number of seconds to show the dialog timer for before locking.
     */
    'session_timeout_dialog_showtime' => 30,

    /**
     * Set to false to not allow withdrawing from privacy statement.
     */
    'gdpr_allow_withdraw' => true,

    /**
     * Id of the Email Template that allows for free text entry.
     */
    'email_template_free_template_id' => 1
];

要求 Uxcrud

composer require heiw/uxcrudible

设置 Laravel

现在您可以在应用中使用 Uxcrud 设置 Laravel。

routes\web.php 中添加

use Heiw\Uxcrudible\Facades\AuthTranslation;

并将

Auth::routes();

替换为

AuthTranslation::routes(['register' => false]);

从数据库中删除默认用户迁移文件

database\migrations\2014_10_12_000000_create_users_table.php

添加 HEIW 包(可选)

HEIW NHS 包是可选的,可以通过运行来要求

composer require heiw/nhs

添加包服务提供者

将包服务提供者添加到 config/app.php

/*
 * Package Service Providers...
 */
\Heiw\Uxcrudible\UxcrudibleServiceProvider::class,

添加中间件

将页面权限添加到 app/Http/Kernel.php

protected $routeMiddleware = [
    // :: add to the bottom of list of middle ware
    'pagePermission' => \Heiw\Uxcrudible\Middleware\PagePermissionMiddleware::class
];

从 Uxcrudible 扩展用户

要使用 Uxcrud,您需要在 App/User.php 中创建一个 User 类,该类扩展了 \Heiw\Uxcrudible\Models\User

<?php

namespace App;

class User extends \Heiw\Uxcrudible\Models\User
{

}

同时,编辑任何现有的 UserApp/Models/User.php 中以扩展上述用户

// ...
class User extends \App\User
// ...

创建用户策略

确保在创建的 app\Policies\UserPolicy.php 中的默认 UserPolicy 调用 UxcrudUserPolicy。

<?php

namespace App\Policies;

use Heiw\Uxcrudible\Policies\UxcrudUserPolicy;

class UserPolicy extends UxcrudUserPolicy
{

}

复制公共资产

为了将公共资产复制到正确位置,请在安装后运行以下命令。

php artisan vendor:publish --tag=public --force

启用可翻译

要启用,运行

php artisan vendor:publish --tag=translatable --force

配置请按照 /vendor/heiw/uxcrudible/docs/translatable.md 中的说明进行

禁用严格

config/database.php 中将 mysql 连接的 strict 更改为 false

    'connections' => [
           ::
        'mysql' => [
                ::
            'strict' => false

生成默认表

对于全新的数据库,运行

php artisan migrate:refresh --seed
php artisan db:seed --class=Heiw\Uxcrudible\Seeds\DatabaseSeeder

对于升级现有数据库,运行以下两个单独的命令。

php artisan migrate
php artisan db:seed --class=Heiw\Uxcrudible\Seeds\DatabaseSeeder

一旦用户表已经填充,您可以选择重置密码或创建自己的账户。

php artisan tinker

在 Tinker 控制台中

$users = \App\Models\User::all(['id', 'lastname']);
dump($users);

一旦您确定了您的账户,就可以设置密码

$yourAccount = \App\Models\User::find(7); // where 7 is your account id from the dump
$yourAccount->password = \Illuminate\Support\Facades\Hash::make('password');
$yourAccount->save();
$yourAccount->refresh();
dd($yourAccount); // Your account will now show the 'password' hash

登录

如果一切顺利,您现在可以登录了!

要强制登录,请打开浏览器到您的应用程序主机名 /admin/settings。