定制 justin0122/crud 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

justin0122/crud

Composer 安装命令:

composer require justin0122/crud

包简介

crud - A simple Laravel package.

README 文档

README

Dependencies

This package requires the following dependencies:

Pre-requisites

To install the package, you need to set the minimum stability to dev in the composer.json file:

{
...
    "minimum-stability": "dev",
    "prefer-stable": true
}

Installation

composer require justin0122/crud

Configuration

Add the service provider to the bootstrap/providers.php file:

# config/app.php

'providers' => [
    ...
    \Justin0122\Crud\CrudServiceProvider::class,
    ...
],

Usage:

To generate a crud, run the following command:

php artisan crud:make Post
Post is the name of the model.

This will generate the following files:

app/Livewire/Post.php
app/Livewire/Posts.php
app/Models/Post.php

database/migrations/2021_01_01_000000_create_posts_table.php

resources/views/livewire/posts/index.blade.php
resources/views/livewire/crud/create.blade.php
resources/views/livewire/crud/edit.blade.php
Details

Forms

The forms are created using the $fillables array in the model. If you want to add more fields, just add them to the array in the model.

Views

Because the forms are generated dynamically, they are made global. This means that you can use them in other views as well. The views are located in the resources/views/livewire/crud folder.

Adding the fillable fields

To make the crud work, you need to add the fillable fields in the model:

# app/Models/Post.php

protected $fillable = [
    'title',
    'body',
];

Adding the routes

Add the routes in the web.php file:

# routes/web.php

use App\Http\Livewire\Post;

    Route::get('/post', fn() => view('post'))->name('post');

    Route::delete('/post/{id}', fn($id) => redirect()->route('post'))->name('post.delete');

    Route::get('/post?id={id}', fn($id) => view('post'))->name('post.edit');

Adding the Livewire component

Add the Livewire component to the view:

<!-- resources/views/post.blade.php -->

<x-layouts.app :title="__('Posts')">
    <livewire:post />
</x-layouts.app>

Displaying the Posts

<!-- resources/views/livewires/posts/index.blade.php -->

<x-table :results="$results" :type="post" :crud="true" :fillables="$fillables"/>

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-27