edujugon / laravel-extra-features
此包为您的Laravel项目提供了有用的功能,以提供额外的功能。
v1.0.2
2016-10-26 18:17 UTC
Requires
- illuminate/support: ^5.2
- nesbot/carbon: ^1.21
Requires (Dev)
- phpunit/phpunit: ^5.6
This package is auto-updated.
Last update: 2024-09-19 09:34:48 UTC
README
此包为您的Laravel项目提供了有用的功能,以提供额外的功能。
安装
在控制台输入
composer require edujugon/laravel-extra-features
Laravel 5.*
通过将其添加到提供者数组中注册包服务。
重要!确保将此行放置在提供者列表的末尾。
'providers' => array(
...
Edujugon\LaravelExtraFeatures\Providers\LaravelExtraFeaturesServiceProvider::class
)
将包的配置文件发布到应用程序的配置目录
php artisan vendor:publish --tag=ExtraFeaturesConfig
上面的行将在config文件夹下创建一个名为extrafeatures.php
的文件。
功能列表
功能
特质
服务
- [QueryCreator](https://github.com/edujugon/LaravelExtraFeatures#querycreator)
重定向找不到页面
当用户尝试加载一个未知的URL时,它会被重定向到特定的已知URL。
非常重要,此功能不会在本地环境中工作。这是一个故意的行为,不是为了隐藏任何重定向/请求错误。
- 转到
config/extrafeatures.php
文件,并更新REDIRECT_NO_PAGE_FOUND
键的值。
Carbon区域设置
Carbon语言基于Laravel的应用程序区域设置设置。默认情况下已启用。您可以通过将CARBON_LOCALE
值更改为false
在config/extrafeatures.php
文件中禁用它。
DateScopesTrait
为Laravel Eloquent提供额外功能,以获取年、月和日的数据。
将 $dateColumn 添加为模型类的属性,您不需要将 $dateColumn 参数传递给方法。
/** * Get items of passed year * If no year, returns Items of current year * * @param $query * @param $column * @param null $year * @return mixed */ public function scopeYear($query,$dateColumn = null,$year = null)
/** * Get items of passed month * If no month, take current month * If no year, take current year * * @param $query * @param $column * @param null $month * @param null $year * @return mixed */ public function scopeMonth($query,$dateColumn = null,$month = null,$year = null)
/** * Get items of passed day. * If no day, take current day * If no month, take current month * If no year, take current year * * @param $query * @param $column * @param null $day * @param null $month * @param null $year * @return mixed */ public function scopeDay($query,$dateColumn = null,$day = null, $month = null, $year = null)
QueryCreator
动态创建数据库查询
/** * Create a query dynamically with passed parameters. * * Params: * tableName is the table name. * array is a list of data to be converted to query. * * @param $tableName * @param array $array * @return mixed */ static public function dynamic($tableName, array $array)
API列表
表格
table
方法为查询设置表名。
语法
object table($tableName)
#####构建
build
方法根据传入的数组构建查询。
语法
object build(arrray $data)
用例
$array = [ '<'=>['pvr'=>'pvl'], 'like'=>['id_imagen'=>'"%5047%"'], 'null'=>['margen_1'] ]; QueryCreator::dynamic('products',$array)->select('id','id_imagen')->first());