定制 codewiser/laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

codewiser/laravel

最新稳定版本:v1.1.10

Composer 安装命令:

composer require codewiser/laravel

包简介

Packages I might include to every Laravel application

README 文档

README

Packages I might include to every Laravel application

Structures

Structure is an array or json attributes with structured interface.

For example:

use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\Casts\AsStringable;
use Illuminate\Support\Stringable;

/**
 * @property null|Stringable $first_name
 * @property null|Stringable $second_name
 * @property null|Stringable $family_name
 */
class Username extends Pivot
{
    protected function casts(): array
    {
        return [
            'first_name' => AsStringable::class,
            'second_name' => AsStringable::class,
            'family_name' => AsStringable::class,
        ];   
    }
} 

Apply Username struct to User model:

use Illuminate\Database\Eloquent\Model;
use Codewiser\Database\Eloquent\Casts\AsStruct;

/**
 * @property null|Username $name
 */
class User extends Model
{
    protected function casts(): array
    {
        return [
            'name' => AsStruct::using(Username::class)
        ];
    }    
}

You can make it not-nullable:

use Illuminate\Database\Eloquent\Model;
use Codewiser\Database\Eloquent\Casts\AsStruct;

/**
 * @property Username $name
 */
class User extends Model
{
    protected function casts(): array
    {
        return [
            'name' => AsStruct::using(Username::class, required: true)
        ];
    }    
}

Structure collections

The same way, you may cast collections of custom structs:

use Codewiser\Database\Eloquent\Casts\AsStructCollection;
use \Illuminate\Support\Collection;

/**
 * @property null|Collection<Contact> $contacts_1
 * @property null|ContactCollection<Contact> $contacts_2
 * @property Collection<Contact> $contacts_3
 */
class User extends Model
{
    protected function casts(): array
    {
        return [
            'contacts_1' => AsStructCollection::using(Contact::class),
            'contacts_2' => AsStructCollection::using(ContactCollection::class, Contact::class),
            'contacts_3' => AsStructCollection::using(Contact::class, required: true),
        ];
    }    
}

Passive SoftDeletes

PassiveSoftDeletes traits works alike SoftDeletes, but it is disabled by default.

Also, it counts record as trashed only then deleted_at is reached. So you may trash records in perspective.

It comes with \Codewiser\Database\Eloquent\Traits\HasDeletedAt trait, that is applicable to custom builders with the same behavior.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-27