remoblaser/resourceful
最新稳定版本:1.0.1
Composer 安装命令:
composer require remoblaser/resourceful
包简介
Create Migration, Seed, Request, Controller, Model and Views for your resource
README 文档
README
Table of Contents
Laravel Resourceful
Resourceful let's you create a full Resource withing seconds! Create a Resource with all the CRUD methods on every layer. Use the artisan command and let it create a Migration, Seed, Request, Controller, Model and Views for your Resource! You're now able to exclude certain parts with --exclude. See the example!
NOTE!
This is a first draft, feel free to create pull requests. Might have a lot of bugs so be careful with the usage! Will continue working on it, tests are yet to come.
Usage
Install through composer
`composer require remoblaser/resourceful --dev``
Add Service Provider
You probably don't want this on your production server, so instead of adding it to the config/app.ch we add it in app/Providers/AppServiceProvider.php. here's a example:
Since we're using Jeffrey Way's / Laracats's Generators, we also need to register his ServiceProvider. Here's a example:
public function register() { if ($this->app->environment() == 'local') { $this->app->register('Remoblaser\Resourceful\ResourcefulServiceProvider'); $this->app->register('Laracasts\Generators\GeneratorsServiceProvider'); } }
Run it!
Now you can use the command. I've extracted everything in single commands so you're able to use the make:resource:controller command if you would like to create only the Controllers the resourceful way.
The make:resource:views command is seperate too, so feel free to use this one aswell.
With the route:extend command, you're able to extend your routes.php file with a resource controller.
The new command route:bind binds a route to your model.
With the -b option, you can do this automatically when generating a resource.
If you want to see all the options, use make:resource -h.
Example
I would like to have a News Resource. I want to have all the CRUD functionality for it. So instead of creating all the Stuff by hand, i can use php artisan make:resource news to generate all the necessary stuff or just use single parts:
$> php artisan make:resource news
Model created successfully.
Created Migration: 2015_04_17_083658_create_news_table
Seed created successfully.
Request created successfully.
Controller created successfully.
Views created successfully.
Routes successfully extended.
With the --exclude option you're able to exclude the Controller, Migration, Seed, Model and/or Views.
If you would like to generate everything except for the Views and the Seed, you can just use --exclude=views,seed.
You're able to submit a --commands option and choose which Actions/Commands you would like to have, commands need to be seperated with a ",". The following commands are available: create, store, show, index, edit, update, destroy
Generated Controller
<?php namespace App\Http\Controllers; use App\Http\Requests; use App\Http\Controllers\Controller; use App\News; use App\Http\Requests\NewsRequest; use Illuminate\Http\Request; class NewsController extends Controller { /** * Display a listing of the resource. * * @return Response */ public function index() { $news = News::all(); return view('news.index', compact('news')); } /** * Show the form for creating a new resource. * * @return Response */ public function create() { return view('news.create'); } /** * Store a newly created resource in storage. * * @param NewsRequest $request * @return Response */ public function store(NewsRequest $request) { News::create($request->all()); return redirect('/news'); } /** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $news = News::find($id); return view('news.show', compact('news')); } /** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $news = News::find($id); return view('news.edit', compact('news')); } /** * Update the specified resource in storage. * * @param int $id * @param NewsRequest $request * @return Response */ public function update(NewsRequest $request ,$id) { $news = News::find($id); $news->update($request->all()); return redirect('/news'); } /** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $news = News::find($id); $news->destroy(); return redirect('/news'); } }
Generated Views
Make sure to include Illuminate/HTML, since the Views are built with it.
create.blade.php
@extends('app') @section('content') {!! Form::open(['route' => 'news.store'], 'method' => 'post']) !!} @include('news.partials.form', ['buttonText' => 'Create news']) {!! Form::close() !!} {{-- @include('errors.validation') --}} @stop
edit.blade.php
@extends('app') @section('content') {!! Form::open(['route' => ['news.update', $news->id]], 'method' => 'post']) !!} @include('news.partials.form', ['buttonText' => 'Update news']) {!! Form::close() !!} {{-- @include('errors.validation') --}} @stop
index.blade.php
@extends('app') @section('content') @foreach($newss as $news) {!! var_dump($news)) !!} @endforeach @stop
show.blade.php
@extends('app') @section('content') {!! var_dump($news) !!} @stop
Info
If you like my work, i would appreciate it if you would spread it! Thank you! You can contact me through Twitter
remoblaser/resourceful 适用场景与选型建议
remoblaser/resourceful 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 287 次下载、GitHub Stars 达 62, 最近一次更新时间为 2015 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「laravel」 「resource」 「artisan」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 remoblaser/resourceful 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 remoblaser/resourceful 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 remoblaser/resourceful 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Generates URLs for public Puli resources.
Add the resource system to symfony application
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Adds support for singular resource routes to the Laravel router.
Retrieve a WebResourceInterface instance over HTTP
统计信息
- 总下载量: 287
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 63
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-17