承接 webdev/laravel-loader 相关项目开发

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

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

webdev/laravel-loader

Composer 安装命令:

composer require webdev/laravel-loader

包简介

Laravel loader

README 文档

README

License

Laravel loader is open-sourced software licensed under the MIT license

Documentation

To get started with Loader, use Composer to add the package to your project's dependencies:

composer require webdev/laravel-loader

Configuration

<?php

namespace App\Models;

use WebDev\Loader\LoaderMacro;
use Illuminate\Database\Eloquent\Model;

abstract class BaseModel extends Model
{
    use LoaderMacro;
}

Basic Usage

$product = Product::findOrFail($id);

return $product->loader(
       new ProductTranslate(new Language()),
       new ProductFeature(new Language()),
       'categories'
);

Product -> translate

class ProductTranslate extends Loader
{

    protected $name = 'translate';

    // Translate
    public function init()
    {
        return ProductTranslate::where('product_id', $this->getModel()->id)
            ->where('language_id' => auth()->user()->language_id)
            ->firts()
            ->toArray();
    }
}

Product -> Product features

class ProductFeature extends Loader
{

    protected $name = 'features';

    // Features
    public function init()
    {
        return ProductFeature::where('product_id', $this->getModel()->id)->get()->toArray();
    }
}

Product -> translate -> language && Product -> product features -> language

class Language extends Loader
{

    protected $name = 'language';

    // Feature
    public function init()
    {
        return Language::findOrFail($this->getPrevious()->language_id)->toArray();
    }
}

Result

array:2 [
  "translate" => array:5 [
    "id" => 4
    "name" => "Product name"
    "description" => "Description"
    "language_id" => 40
    "language" => array:6 [
      "id" => 40
      "code" => "en"
      "flag" => null
      "name" => "English"
      "native_name" => "English"
      "is_active" => 1
    ]
  ]
  "features" => array:2 [
    0 => array:2 [
      "id" => 23
      "name" => "Feature1"
      "feature_id" => 14
      "language_id" => 40
      "language" => array:6 [
        "id" => 40
        "code" => "en"
        "flag" => null
        "name" => "English"
        "native_name" => "English"
        "is_active" => 1
      ]
    ]
    1 => array:5 [
      "id" => 24
      "name" => "TH"
      "feature_id" => 14
      "language_id" => 156
      "language" => array:6 [
        "id" => 156
        "code" => "th"
        "flag" => null
        "name" => "Thai"
        "native_name" => "ไทย"
        "is_active" => 1
      ]
    ]
  ],
  "categories" => ...
]

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固