定制 wearepixel/laravel-model-objects 二次开发

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

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

wearepixel/laravel-model-objects

最新稳定版本:1.0.0

Composer 安装命令:

composer require wearepixel/laravel-model-objects

包简介

A package to easily serialize a Laravel model to be stored in a database for disconnected model access.

README 文档

README

Latest Version on Packagist Total Downloads GitHub Actions

A package to easily retrieve model objects for easy storage in Laravel

Key Features

  • Retrieve an object from a model
  • Hide fields from the object by using the $hiddenProperties array property
  • Hide relationships from the object by setting a config value

Installation

You can install the package via composer:

composer require wearepixel/laravel-model-objects

Usage

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use WeArePixel\LaravelModelObjects\HasModelObject;

class User extends Model
{
    use HasModelObject;

    protected $hiddenProperties = [
        'user_id',
    ];
}

// ...
$user = User::find(1);
$userObject = $user->modelObject;

Configuration

Publshing The Configuration

The configuration file looks like this:

return [
    /**
     * Hide the primary key from the model object
     */
    'hide_primary_key' => env('LARAVEL_MODEL_OBJECTS_HIDE_PRIMARY_KEY', true),

    /**
     * Hide timestamps from the model object
     */
    'hide_timestamps' => env('LARAVEL_MODEL_OBJECTS_HIDE_TIMESTAMPS', true),
];

If you need to make any changes to the configuration, feel free to publish the configuration file.

php artisan vendor:publish --provider="WeArePixel\LaravelModelObjects\LaravelModelObjectsServiceProvider"

Hiding Model Attributes

This package will automatically hide any additional fields, you add into $hiddenProperties array property.

protected $hiddenProperties = [
    'user_id',
];

This is useful for scenarios where you don't need to store all fields in the object, or you want to hide sensitive information.

Testing

composer test

License

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

统计信息

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

GitHub 信息

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

其他信息

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