承接 iceylan/restorm 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

iceylan/restorm

最新稳定版本:v2.0.0

Composer 安装命令:

composer require iceylan/restorm

包简介

A Laravel plugin that feeds the Restorm in harmony running on the client side.

README 文档

README

This composer package allows us to handle requests properly in Laravel that sent by the Restorm javascript library from client side.

Installation

To install the package, run the following command in terminal, on your laravel project's root path:

composer require iceylan/restorm

Usage

Let's just keep things simple, we can use it in laravel routes/api.php file like:

use App\Models\Post;
use Iceylan\Restorm\Restorm;

Route::get( 'v1.0/posts', function( Restorm $restorm )
{
	return $restorm
		->apply( Post::class )
		->get();
});

And server can easily respond the request like:

GET /api/v1.0/posts?with=author&filter[author_id]=eq:12&sort[created_at]=desc&limit=10&page=1&paginate=length-aware

If the endpoint is not a collection of resources, then we should grab the model the Laravel way like:

use App\Models\Post;
use Iceylan\Restorm\Restorm;

Route::get( 'v1.0/posts/{post}', function( Restorm $restorm, Post $post )
{
	return $restorm
		->apply( $post )
		->get();
});

We can pass the following types as a parameter to the apply method:

  • fully qualified class name like App\Models\Post
  • query builders like Post::where( 'id', 1 )
  • relations Post::with( 'user' )
  • model instances like Post::find( 1 )
  • model classes like Post::class which will return App\Models\Post

Restorm will parse the request and make modification on the model that we just passed to it, depending on the directives that carried by the request.

It will return the QueryBuilder, Model, Relation, or whatever we passed at the first stage. It will be back with the modifications applied to it. We can continue to work with that source as we did before in Laravel.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-19