定制 aminul/crudgenerator 二次开发

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

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

aminul/crudgenerator

Composer 安装命令:

composer require aminul/crudgenerator

包简介

A simple Laravel library that allows you to create crud operations with a single command

README 文档

README

A simple Laravel 8.* library that allows you to create crud operations with a single command

Installation

composer require aminul/crudgenerator

Features

  • Controller (with all the code already written)
  • Model
  • Migration
  • Requests
  • Routes

Enable the package (Optional)

This package implements Laravel auto-discovery feature. After you install it the package provider and facade are added automatically

Configuration

Publish the configuration file

This step is required

php artisan vendor:publish --provider="Aminul\CrudGenerator\CrudGeneratorServiceProvider"

Usage

After publishing the configuration file just run the below command

php artisan make:crud ModelName

Just it, Now all of your Model Controller, Migration, routes and Request will be created automatically with all the code required for basic crud operations

Example

php artisan make:crud Product

ProductController.php

<?php

namespace App\Http\Controllers;

use App\Http\Requests\ProductRequest;
use App\Product;

class ProductController extends Controller
{
    public function index()
    {
        $Products = Product::latest()->get();

        return response()->json($Products, 201);
    }

    public function store(ProductRequest $request)
    {
        $Product = Product::create($request->all());

        return response()->json($Product, 201);
    }

    public function show($id)
    {
        $Product = Product::findOrFail($id);

        return response()->json($Product);
    }

    public function update(ProductRequest $request, $id)
    {
        $Product = Product::findOrFail($id);
        $Product->update($request->all());

        return response()->json($Product, 200);
    }

    public function destroy($id)
    {
        Product::destroy($id);

        return response()->json(null, 204);
    }
}

Product.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $guarded = ['id'];
}

ProductRequest.php

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ProductRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [];
    }
}

products table migration

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
    }
}

Routes/web.php

Route::resource('products', 'ProductController'); 
Now all of your basic apis are ready to use you can use them directly by just adding fields in your table

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固