承接 achrafbardan/simple-resources 相关项目开发

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

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

achrafbardan/simple-resources

最新稳定版本:2.0.0

Composer 安装命令:

composer require achrafbardan/simple-resources

包简介

This is my package simple-resources-for-laravel

README 文档

README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

This is a small package that simplifies resource usage. It is used to auto guess and link resources to models. Paginated collections are also auto wrappable in the resource.

Installation

You can install the package via composer:

composer require AchrafBardan/simple-resources-for-laravel

You can publish the config file with:

php artisan vendor:publish --tag="simple-resources-for-laravel-config"

This is the contents of the published config file:

return [
    "model_namespace" => "App\\Models",
    "resource_namespace" => "App\\Http\\Resources",

    /**
     * When this is set to false, you have to add the \AchrafBardan\SimpleResources\Contracts\HasResource interface to your models.
     * When set to true you can still optionally add the interface to your models, this interface will than be used instead of the guesser.
     */
    "guess_resource" => true
];

Optionally, you can publish the views using

php artisan vendor:publish --tag="simple-resources-for-laravel-views"

Usage

Before returning a model or collection you pass it trough the ResourceFactory. The resource factory finds the resource for your model, collection or even a paginated collection.

use AchrafBardan\SimpleResources\ResourceFactory;
...
$resource = ResourceFactory::make($model);
return response()->json($resource);

You can also use the helper function resource which is the same as ResourceFactory::make

use function AchrafBardan\SimpleResources\resource;
...
$resource = resource($model);
return response()->json($resource);

It also intended to be used inside a resource for child models and collections, see the following example.

// App/Http/Resources/TestResource.php
...
class TestResource extends JsonResource
{
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'child' => resource($this->whenLoaded('child'))
        ];
    }
}

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固