diviky / bright
框架扩展
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.2
- kirschbaum-development/eloquent-power-joins: ^3.5
- laravel/framework: ^10.2
- laravel/sanctum: ^3.0
- laravel/ui: ^4.2
- league/flysystem-aws-s3-v3: ^3.10
- matomo/decompress: ^2.1
- mongodb/laravel-mongodb: ^4.5
- schuppo/password-strength: ^2.6
- spatie/laravel-permission: ^6.9
- spatie/laravel-schemaless-attributes: ^2.3
Requires (Dev)
- diviky/code-analysis: ^2.0
- laravel/socialite: ^5.0
- league/oauth2-client: ^2.6
Suggests
- consoletvs/charts: ^6.2
- geocoder-php/chain-provider: ^4.0
- geocoder-php/common-http: ^4.0
- geocoder-php/geoip2-provider: ^4.0
- geoip2/geoip2: ^2.9
- laravel/socialite: ^5.0
- matomo/decompress: ^2.1
- matomo/device-detector: ^3.12
- portphp/csv: ^1.1
- portphp/excel: ^1.1
- portphp/portphp: ^1.3
- symfony/yaml: *
- willdurand/geocoder: ^4.2
- v5.0.3
- v5.0.2
- v5.0.1
- v5.0.0
- 4.x-dev
- v4.1.11
- v4.1.10
- v4.1.9
- v4.1.8
- v4.1.7
- v4.1.6
- v4.1.5
- v4.1.4
- v4.1.3
- v4.1.2
- v4.1.1
- v4.1.0
- v4.0.32
- v4.0.31
- v4.0.30
- v4.0.29
- v4.0.28
- v4.0.27
- v4.0.26
- v4.0.25
- v4.0.24
- v4.0.23
- v4.0.22
- v4.0.21
- v4.0.20
- v4.0.19
- v4.0.18
- v4.0.17
- v4.0.16
- v4.0.15
- v4.0.14
- v4.0.13
- v4.0.12
- v4.0.11
- v4.0.10
- v4.0.9
- v4.0.8
- v4.0.7
- v4.0.6
- v4.0.5
- v4.0.4
- v4.0.3
- v4.0.2
- v4.0.1
- 3.x-dev
- v3.1.7
- v3.1.6
- v3.1.5
- v3.1.4
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.10
- v3.0.9
- v3.0.8
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- 2.x-dev
- dev-master / 2.x-dev
- v2.2.8
- v2.2.7
- v2.2.6
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.50
- v2.1.49
- v2.1.48
- v2.1.47
- v2.1.46
- v2.1.45
- v2.1.44
- v2.1.43
- v2.1.42
- v2.1.41
- v2.1.40
- v2.1.39
- v2.1.38
- v2.1.37
- v2.1.36
- v2.1.35
- v2.1.34
- v2.1.33
- v2.1.32
- v2.1.31
- v2.1.30
- v2.1.29
- v2.1.28
- v2.1.27
- v2.1.26
- v2.1.25
- v2.1.24
- v2.1.23
- v2.1.22
- v2.1.21
- v2.1.20
- v2.1.19
- v2.1.18
- v2.1.17
- v2.1.16
- v2.1.15
- v2.1.14
- v2.1.13
- v2.1.12
- v2.1.11
- v2.1.10
- v2.1.9
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.38
- v2.0.37
- v2.0.36
- v2.0.35
- v2.0.34
- v2.0.33
- v2.0.32
- v2.0.31
- v2.0.30
- v2.0.29
- v2.0.28
- v2.0.27
- v2.0.26
- v2.0.25
- v2.0.24
- v2.0.23
- v2.0.22
- v2.0.21
- v2.0.20
- v2.0.19
- v2.0.18
- v2.0.17
- v2.0.16
- v2.0.15
- v2.0.14
- v2.0.13
- v2.0.12
- v2.0.11
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v1.x-dev
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- 1.0.3
- v1.0.2
- v1.0.1
- dev-dependabot/composer/mongodb/laravel-mongodb-5.0.2
This package is auto-updated.
Last update: 2024-09-23 23:27:31 UTC
README
安装
composer require diviky/bright
通过输入值过滤查询
$filters = []; // $query->whereRaw('date(created_at) = ?', ['2019-10-12']) $filters[] = ['date[created_at]' => date('Y-m-d')]; // $query->whereDateBetween('created_at between ? and ? ', ['2019-10-12', '2019-10-22']) $filters[] = ['range[created_at]' => date('Y-m-d') .' - '. date('Y-m-d')]; // $query->whereBetween('created between ? and ? ', [strtotime('-1 day'), time()]) $filters[] = ['timestamp[created]' => date('Y-m-d') .' - '. date('Y-m-d')]; // $filters[] = ['unixtime[created]' => date('Y-m-d') .' - '. date('Y-m-d')]; $filters[] = ['between[created]' => date('Y-m-d') .' - '. date('Y-m-d')]; $filters[] = ['filter[name]' => 'bright']; // $query->where('name', '=', 'bright') $filters[] = ['filter[first_name|last_name]' => 'bright']; // $query->where('first_name', '=', 'bright')->orWhere() $filters[] = ['lfilter[name]' => 'bright']; // $query->where('name', 'like', '%bright%') $filters[] = ['rfilter[name]' => 'bright']; // $query->where('name', 'like', 'bright%') $filters[] = ['efilter[name]' => 'bright']; // $query->where('name', 'like', '%bright') $rows = DB::table('users') ->filter($filters) ->get();
数据库过滤器
filter
方法用于在查询构建器中过滤数据库列。它接受 requets
对象作为 array
。
可用过滤器
filter[]
使用 $builder->where($column, $value)
。使用数组键作为列名,值作为值。例如:filter[column]='value'
lfilter[]
使用 $builder->where($column, '%'.$value.'%')
进行模糊匹配。使用数组键作为列名,值作为值。例如:lfilter[column]='value'
使用 |
符号进行过滤或条件。例如:filter[comments|title]=xxx
使用 :
符号通过关系表进行过滤。例如:filter[posts:title]=xxx
使用 .
符号在连接查询中过滤表别名。例如:filter[comments.title]=xxx
使用 scope[]
过滤模型作用域。例如:scope[status]=1
将执行 $builder->status(1)
使用 parse[]
对过滤查询语言进行 DSL 解析。此语言中的示例查询
price = 100
price != 100
price > 100
price < 100
price <= 100
price >= 100
name =~ "brig%"
price > 100 AND active = 1
status = "pending" OR status = "approved"
product.price > 100 AND category.id = 7
product:price > 100 AND category:id = 7
name =~ "Foo%"
created_at > "2017-01-01" and created_at < "2017-01-31"
status = 1 AND (name = "PHP Rocks" or name = "I ♥ PHP")
模型关系
返回合并了关系属性的单一模型
flattern
flattern($except, $exlcude)
方法将关系的键和值合并到主模型属性中并返回组合属性。如果关系键与主键相同,则关系键将覆盖主键。
use App\Models\User; $rows = Book::with('author')->get(); $rows->transform(function($row) { return $row->flattern(); });
flat
flat($except, $exlcude)
方法将关系的键和值合并到主模型属性中并返回组合属性。
use App\Models\User; $rows = Book::with('author')->get(); $rows->transform(function($row) { return $row->flat(); });
some
some($keys)
方法从关系和主模型中获取一些键。
use App\Models\User; $rows = Book::with('author')->get(); $rows->transform(function($row) { return $row->some(['id', 'author.name']); });
except
except($keys)
方法从关系和主模型中获取一些键。
use App\Models\User; $rows = Book::with('author')->get(); $rows->transform(function($row) { return $row->except(['author.id']); });
merge
merge($keys)
方法将额外的键值对添加到模型属性中。
use App\Models\User; $rows = Book::with('author')->get(); $rows->transform(function($row) { return $row->merge(['extra' => 'value']); });
concat
concat($keys)
方法将关系键值添加到属性中。
use App\Models\User; $rows = Book::with('author')->get(); $rows->transform(function($row) { return $row->concat(['author.id','author.name']); });
combine
combine($keys)
方法合并和连接关系和属性。
use App\Models\User; $rows = Book::with('author')->get(); $rows->transform(function($row) { return $row->combine(['author.id', 'author.name']); });
Eloquent:集合
flatterns
flatterns($except, $exlcude)
方法将关系的键和值合并到主模型属性中并返回组合属性。如果关系键与主键相同,则关系键将覆盖主键。
use App\Models\User; $books = Book::with('author')->get(); $books = $books->flatterns($except, $exclude);
flats
flats($except, $exlcude)
方法将关系的键和值合并到主模型属性中并返回组合属性。
use App\Models\User; $books = Book::with('author')->get(); $books = $books->flats($except, $exclude);
few
few($keys)
方法从关系和主模型中获取一些键。
use App\Models\User; $books = Book::with('author')->get(); $books = $books->few(['id', 'author.name']);
扁平化关系
返回合并了关系属性的单一模型
// except the relations from merge $model = $model->flatten($except); // Take some keys $model = $model->some(['id']); // Take except $model = $model->except(['id']); // Append keys to attributes $model = $model->merge(['id' => 1]); // Apped relation keys to attributes $model = $model->concat(['relation.id']); // combination of merge and contact $model = $model->combine(['relation.id']);
排序任务
<tbody ajax-content class="table_sortable_body"> ... <td sortable> <i class="fa fa-arrows-v fa-lg"></i> <input type="hidden" name="sorting[{{ $row->id }}]" value="{{ $row->ordering }}" /> </td> </tbody>
if ($task == 'sorting') { $sorting = $this->input('sorting'); $this->get('resolver')->getHelper('speed')->sorting('table', $sorting, 'id'); return []; }
构建器扩展方法
搜索多个列和关系
Post::whereLike(['name', 'text', 'author.name', 'tags.name'], $searchTerm)->get();
迭代结果
如果您喜欢,可以通过分块和回调修改来获取所有行
$rows = DB::table('large_table')->iterate(1000); $rows = DB::table('large_table')->iterate(1000, function($row) { return $row; });
从多张表中获取结果
如果您有多张表中的数据,想要分页检索表
$rows = DB::tables(['roles', 'roles1', 'roles2'])->complexPaginate();
缓存查询结果
如果您想缓存结果
$rows = DB::table('uses') ->remember($minutes, $cache_key) ->get(); $rows = DB::table('uses') ->rememberForever($cache_key) ->get();
从查询中删除
$rows = DB::table('users') ->filter($filters) ->deletes();
$rows = DB::table('users') ->whereDateBetween('created_at', [date(), date()]) ->get();
获取已删除和未删除的
获取未删除的项目
$rows = DB::table('users') ->withOutTrashed() ->get();
仅获取已删除的项目
$rows = DB::table('users') ->onlyTrashed() ->get();
原始表达式
$rows = DB::table('orders') ->groupByRaw(['username']); ->groupByRaw('price * ? as price_with_tax', [1.0825]); ->get()
$rows = DB::table('orders') ->selectRaw(['max(price)', 'order_id']); ->groupByRaw('price * ? as price_with_tax', [1.0825]); ->get()
$rows = DB::table('orders') ->selectRaw(['max(price)', 'order_id']); ->whereBetweenRaw('max(price)', [1.0825, 2]); ->get()
排序
$rows = DB::table('orders') ->ordering($data, ['order_id' => 'desc']); ->groupByRaw('price * ? as price_with_tax', [1.0825]); ->get()
时间戳
设置时间戳 'created_at和
updated_at以插入和
updated_at`以更新
$result = DB::table('orders') ->timestamps() ->insert($values)
$result = DB::table('orders') ->timestamps() ->update($values)
$result = DB::table('orders') ->timestamps(false) ->update($values)
<select name="sent_by" class="form-control" data-select data-select-fetch="{{ url('search/employee') }}" data-fetch-method="post" data-selected="2" label-field="name" value-field="employe_id"> <option value="">Search Employee</option> </select>
<select name="sent_by" tokenizer> <option value="">Search Employee</option> </select>
<select name="sent_by" data-select-ajax="{{ url('search/employee') }}"> <option value="">Search Employee</option> </select>
<select name="sent_by" data-select-image="{{ url('search/employee') }}"> <option value="">Search Employee</option> </select>
<select name="countries" data-select-target="#states" data-method="get" data-url="{{ url('search/states/:id') }}"> <option value="">Search Country</option> </select> <select name="states" id="states" > <option value="">Search State</option> </select>
:id
将被替换为国家ID以获取州列表
属性
在控制器中使用的自定义属性,用于配置视图、资源和布局
可用属性
use Diviky\Bright\Attributes\View;
use Diviky\Bright\Attributes\ViewPaths;
use Diviky\Bright\Attributes\ViewNamespace;
use Diviky\Bright\Attributes\Resource;
use Diviky\Bright\Attributes\ResourceCollection;
#[View('name', 'layout')]
#[View('none')] //No view will be rendered
#[ViewPaths([__DIR__.'views'])]
#[ViewNamespace("package")]
#[Resource('Resources/PostResource', 'post')]
#[ResourceCollection('Resources/PostResource', 'posts')]
#[View('name', 'layout')] // by default method name has view name public function index(Request $request) { $data = $request->all(); $rows = Post::filter($data) ->ordering($data, ['ordering' => 'asc']) ->paginate(); return [ 'rows' => $rows, ]; }
许可证
MIT许可证(MIT)。请参阅许可证文件获取更多信息。