nabil12ful/store-data-requests
Composer 安装命令:
composer require nabil12ful/store-data-requests
包简介
Store data to DB by model from requests fields html form
README 文档
README
Support laravel v8+
Store data to database from (Form Requsts Fields) by Model
Installation
composer require nabil12ful/store-data-requests
To publish
php artisan vendor:publish --provider="Nabil\StoreDataRequestsServiceProvider"
Usage
php artisan make:controller UserController -r
Or
php artisan make:controller UserController -m User
Change this info after controller generation & Congratolations 😄
protected $model = \App\Models\User::class; protected $folderBlade = 'backend.user'; // View folder name OR path protected $uploadPath = 'upload/user'; protected $columns = [ // table columns & fields name 'name', 'email', ]; protected $mediaColumns = [ // columns name have a media files like [Image, Pdf, Doc, etc...] 'image' ];
Views Folder
+--- views | +--- backend | | +--- user | | | +--- index.blade.php | | | +--- create.blade.php | | | +--- edit.blade.php | | | +--- show.blade.php | | +--- product | | | +--- index.blade.php | | | +--- create.blade.php | | | +--- edit.blade.php | | | +--- show.blade.php | | +--- index.blade.php
To use Vaildation
Create request validation by
php artisan make:request UserStoreRequest
public function store(UserStoreRequest $request): RedirectResponse { StoreDataRequests::model($this->model)->make($request, $this->columns)->store($this->uploadPath); }
Or use
First change columns array like:
protected $columns = [ // table columns & fields name with rules 'name' => 'required|string|min:5', 'email' => 'required|email', ]; protected $mediaColumns = [ // table columns & fields name has files with rules 'image' => 'required|image', ];
And use storeValidated, updateValidated methods
public function store(Request $request) { $result = StoreDataRequests::model($this->model)->make($request, $this->columns)->storeValidated('upload/users'); if(isset($result->id)) { toastr()->success('The data has been stored successfully', 'Success'); return redirect()->back(); }else{ return back()->withInput()->withErrors($result); } }
On update
public function update($id, Request $request) { $result = StoreDataRequests::model($this->model)->make($request, $this->columns, $this->mediaColumns)->updateHasFilesValidate($id, $this->uploadPath); if(!$result) { toastr()->success('The data has been updated successfully', 'Success'); return redirect()->back(); }else{ return back()->withInput()->withErrors($result); } }
Delete records
Enter path Param If you want to delete files from uploads path with delete a record:
StoreDataRequests::model($this->model)->delete(decrypt($id), $this->uploadPath);
Use our service in simple Controller
First import our plugin in your Controller file
use Nabil\StoreDataRequests;
And write this code to create a new record:
public function store(Request $request) { StoreDataRequests::model('Prodect')->make($request, ['title','description'])->store(); }
Or write this code to update old record in Database model:
public function update(Request $request, $id) { StoreDataRequests::model('Prodect')->make($request, ['title','description'])->update($id); }
Upload files with insert data
use:
StoreDataRequests::model('Prodect')->make($request, ['title','description'], ['image'])->store('path/to/upload');
or update has file:
StoreDataRequests::model('Prodect')->make($request, ['title','description'], ['image'])->update($id, 'path/to/upload');
Thanks for Eng/Sameh Mohamed
Made with ❤️ By Eng/Nabil Hamada
nabil12ful/store-data-requests 适用场景与选型建议
nabil12ful/store-data-requests 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 52 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 01 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nabil12ful/store-data-requests 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nabil12ful/store-data-requests 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 52
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-01-28