kejojedi/crudify 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kejojedi/crudify

Composer 安装命令:

composer require kejojedi/crudify

包简介

Laravel 7 CRUD app scaffolding & generator.

README 文档

README

Imgur

Crudify

Crudify is a Laravel 7 package which includes sensible CRUD app scaffolding and a generator to make your life easier. It automates initial CRUD app setup with the crudify:install command, and generates CRUD resource files for you with the crudify:generate command. It also includes form components to make creating forms a breeze.

It is configured to work well with PHPStorm, Valet, and Laragon, among others. This package requires Node.js to be installed in order to run npm commands.

Useful links:

Installation

Install Laravel:

laravel new app

Configure .env file:

APP_NAME=App
APP_URL=http://app.test
DB_DATABASE=app
MAIL_USERNAME=mailtrap_username
MAIL_PASSWORD=mailtrap_password
MAIL_FROM_ADDRESS=info@app.test

Require Crudify:

composer require kejojedi/crudify

Install Crudify:

php artisan crudify:install

Visit your app URL and login using:

Email: admin@example.com
Password: password

The AdminUserSeeder call can be removed from your DatabaseSeeder any time.

Generating CRUD

Run crudify:generate for a new model:

php artisan crudify:generate Model

This will generate:

  • Controller
  • Datatable
  • Form Request
  • Model
  • Factory
  • Migration
  • Seeder
  • View Files
  • Navbar Link
  • Routes

Don't forget to migrate after updating the new migration file.

Tip: use the --force in order to replace existing generated files e.g. php artisan crudify:generate Model --force

Datatables

Crudify includes a wrapper for yajra/laravel-datatables-html to make building datatables nice and declarative. Generated model datatable classes are located in app\Http\Datatables.

Declaring columns:

protected function columns()
{
    return [
        Column::make('id'),
        Column::make('name'),
        Column::make('created_at'),
        Column::make('updated_at'),
    ];
}

Different ways of defining default sort order:

protected $order_by = 'id'; // sorts by id, ascending
protected $order_by = ['created_at', 'desc']; // sorts by created_at, descending

protected function orderBy()
{
    return 'id'; // sorts by id, ascending
}

protected function orderBy()
{
    return ['created_at', 'desc']; // sorts by created_at, descending
}

Note: a users per-page entries & sorting preferences are saved per-table in their browser indefinitely, so this will only set the initial default order.

Example of adding methods to the datatables html builder:

protected function htmlMethods(Builder &$html)
{
    $html->ajax([
        'url' => route('users.index'),
        'type' => 'GET',
        'data' => 'function(d) { d.key = "value"; }',
    ]);
}

Example of adding methods to the datatables json builder:

protected function jsonMethods(DataTableAbstract &$datatables)
{
    $datatables->editColumn('name', function(User $user) {
        return 'Hi ' . $user->name . '!';
    });
}

Tip: If you don't want a datatable to have an actions column, simply remove the actions() method entirely.

Form Components

Crudify offers simple form components to make building forms fast & easy. See below for minimal and complete examples of each component.

Input:

<x-crudify-input name="name" :value="old('name', $car->name ?? '')" />
<x-crudify-input name="year" type="number" :label="__('Year')" id="car_year" :value="old('year', $car->year ?? '')" />

Textarea:

<x-crudify-textarea name="description" :value="old('description', $car->description ?? '')" />
<x-crudify-textarea name="description" rows="5" :label="__('Car Description')" id="car_description" :value="old('description', $car->description ?? '')" />

Select:

<x-crudify-select name="fuel_type" :options="['Gas', 'Diesel', 'Electric']" :value="old('fuel_type', $car->fuel_type ?? '')" />
<x-crudify-select name="fuel_type" :options="['Gas', 'Diesel', 'Electric']" :empty="false" :label="__('Car Fuel Type')" id="car_fuel_type" :value="old('fuel_type', $car->fuel_type ?? '')" />

Note: if the options are an associative array, the keys are used as the labels and the values as the values. For sequential arrays, the values are used for both the labels and values.

File:

<x-crudify-file name="image" />
<x-crudify-file name="other_images" :label="__('Other Car Images')" :file-label="__('Choose Images')" id="other_car_images" :multiple="true" />

Checkbox:

<x-crudify-checkbox name="insured" :value="old('insured', $car->insured ?? 0)" />
<x-crudify-checkbox name="insured" :label="__('Insured')" :checkbox-label="__('This car is insured')" id="car_insured" :value="old('insured', $car->insured ?? 0)" />

Note: checkbox attributes should have boolean migration columns.

Checkboxes:

<x-crudify-checkboxes name="features" :options="['Bluetooth', 'Navigation', 'Speakers']" :value="old('features', $car->features ?? [])" />
<x-crudify-checkboxes name="features" :options="['Bluetooth', 'Navigation', 'Speakers']" :label="__('Car Features')" id="car_features" :value="old('features', $car->features ?? [])" />

Note: checkboxes attributes should be cast to array with text migration columns.

Radios:

<x-crudify-radios name="color" :options="['Red' => '#ff0000', 'Green' => '#00ff00', 'Blue' => '#0000ff']" :value="old('color', $car->color ?? '')" />
<x-crudify-radios name="color" :options="['Red' => '#ff0000', 'Green' => '#00ff00', 'Blue' => '#0000ff']" :label="__('Car Color')" id="car_color" :value="old('color', $car->color ?? '')" />

Tip: you can determine if the fields are showing on the create or edit page by checking isset($model) (e.g. isset($car)). If a $model is set, it means the user is on the edit page.

Packages Used

Composer packages:

NPM packages:

统计信息

  • 总下载量: 1.64k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 50
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 50
  • Watchers: 5
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固