2018年11月

react-schema-form

  1. Design with no theme, Has Core Package and Bootstrap package ↑↑
  2. The size of the file after compile is small ↑
  3. Not a stable package ↓
  4. Easy to implement ↑
  5. If field is empty, props in form-data is deleted. ↑
  6. When field is hide, props in form-data is visible. ↓
  7. Custom template is easy ↑↑
  8. Some default template break the style of custom template ↓

React-jsons-form

  1. Design with material-ui ↓
  2. The size of the file after compile is large↓
  3. Stable package ↑
  4. Easy to implement ↑
  5. If field is empty, props in form-data is an empty string ↓
  6. When field is hide, props in form-data is visible ↓
  7. Custom Template is easy ↑
  8. but hard to overwrite default template ↓

ResourceCollection 是用于处理 返回值为json的时候定义返回的集合的格式,集合内的单个元素可以使用 Illuminate\Http\Resources\Json\JsonResource 定义,或者直接在toArray中重新定义。

use App\User;
use App\Http\Resources\User as UserResource;

Route::get('/user', function () {
    return UserResource::collection(User::all());
});

// 如果定义了Collection 

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;

class UserCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'data' => $this->collection,
            'links' => [
                'self' => 'link-value',
            ],
        ];
    }
}
// 新的写法
use App\User;
use App\Http\Resources\UserCollection;

Route::get('/users', function () {
    return new UserCollection(User::all());
});