定制 chrisabey84/laravel-cached-options-list 二次开发

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

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

chrisabey84/laravel-cached-options-list

Composer 安装命令:

composer require chrisabey84/laravel-cached-options-list

包简介

A simple package that allows you to cache all rows on a relationship model for use in select arrays on forms

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A simple package that allows you to cache all rows on a relationship model for use in select arrays on forms.

Installation

You can install the package via composer:

composer require chrisabey84/laravel-cached-options-list

You can publish the config file with:

php artisan vendor:publish --provider="Chrisabey84\LaravelCachedOptionsList\LaravelCachedOptionsListServiceProvider

This is the contents of the published config file:

return [
    'key' => 'id', //The index/key column for the select options array
    'value' => 'name', //The value column for the select options array
];

Usage

Adding the HasCachedOptionsList trait to any of your models will provide the following functionality:

$rows = \App\Models\MyModel::asSelectArray();

Will retrieve all rows as an associative array which can then be used in your blade templates to populate the option in a select box:

<select name="mySelectBox">
@foreach($rows as $key => $value)
	<option value="{{ $key }}">{{ $value }}</option>
@endforeach
</select>

Custom Behavior

By default asSelectArray() will retrieve all rows from the database table however, you can customise this behavior by overriding the following method in your model which must return a Builder instance:

protected static function buildQuery(): Builder
{
	return static::query();
}

Clearing The Cache

The cache will be automatically cleared when creating, updating or deleting your models.

To manually clear the cache, you can either call:

\App\Models\MyModel::clearOptionsCache();

Or use the handy artisan command with the model name as the argument:

php artisan cached-options:clear '\App\Models\MyModel'

Testing

composer test

Credits

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固