laravie/dhosa 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

laravie/dhosa

最新稳定版本:v1.1.0

Composer 安装命令:

composer require laravie/dhosa

包简介

Hot Swapping for Laravel Eloquent

README 文档

README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Dhosa allows developers to implement hot-swapping capabilities on Eloquent models. This will helps package developer to create a base model and app developer can extends upon the base model while making sure that all the relationship uses the proper model.

Installation

To install through composer, run the following command from terminal:

composer require "laravie/dhosa"

Usages

Enable Hot-Swap

To enable hot-swap to any Eloquent all you need to do is use Laravie\Dhosa\Concerns\Swappable and implements the method.

<?php

namespace App\Models;

// ...
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravie\Dhosa\Concerns\Swappable;

class User extends Authenticatable
{
    use Swappable;
    
    /**
     * Get Hot-swappable alias name.
     *
     * @return string
     */
    public static function hsAliasName(): string
    {
        return 'User';
    }
}

Registering Hot-Swap

use Laravie\Dhosa\HotSwap;

HotSwap::register('Orchestra\Model\User');

Overriding Hot-Swap

In the App\Providers\AppServiceProvider we can now override the resolution of User to App\User by adding:

use Laravie\Dhosa\HotSwap;

HotSwap::override('User', 'App\User');

Defining relationship

You can define relationship by using the following code:

use Orchestra\Model\User;

/* ... */

public function user() 
{
    return $this->belongsTo(User::hsFinder());
}

Making queries

use Orchestra\Model\User;

$user = User::hs(); // return instance of App\User

$user = User::hs()->query(); // return a query builder for App\User

$user = User::hsOn('api'); // return a query builder for App\User using `api` db connection.

$user = User::hsOnWriteConnection(); // return a query builder for App\User using write PDO connection.

Helpers methods

use Orchestra\Model\Role;
use Orchestra\Model\User;

User::hsAliasName(); // return "User"

User::hsFinder(); // return "App\User"

Role::hsFinder(); // return "Orchestra\Model\Role"

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-04