bnhashem/file
Composer 安装命令:
composer require bnhashem/file
包简介
CRUD File From Any Section
README 文档
README
Installing File Package
The recommended way to install File Package is through Composer.
composer require bnhashem/file
Storage Link
Creating Shourtcut of storage folder , you will found shortcut by following this path your-project/public
php artisan storage:link
Updating your Provider Array
you should Go to config\app.php , in Provider array you should put this Line:
'providers' => [ /* * Laravel Framework Service Providers... */ Bnhashem\File\FileServiceProvider::class, ],
Store File
use Bnhashem\File\Traits\File; public function store(Request $request) { $post = new Post([ 'image' => File::store('posts' , 'image'), 'banner' => File::store('posts' , 'banner'), ]); $post->save(); // posts is the parent Folder // image and banner are the childs Folders // image and banner also request name , that mean image or banner is required. }
Update File
In update Model function:
- If
$request->imageor$request->banneris Equal null , that mean Nothing Will Not happen - If
$request->imageor$request->banneris Not Equal null , that mean image or banner will removed from Database and Server and store New image that will comming From request
use Bnhashem\File\Traits\File; public function update(Request $request , Post $post) { $post->update([ 'image' = File::update('posts' , 'image' , $post), 'banner' = File::update('posts' , 'banner' , $post), ]); // posts are the parent Folder // image and banner are the childs Folders // image and banner also request name , that mean image or banner is required. // You should pass Row to function }
Destroy File
In destroy Model function: File will removed From Database and also will Removed from server.
use Bnhashem\File\Traits\File; public function destroy(Request $request , Post $post) { File::destroy('image' , $post); File::destroy('banner' , $post); // You should pass Row to function }
How to get file
For Example if you upload photo , you will find it According to this path :
<img src="{{ url('storage/'.$post->image) }}" >
<img src="{{ url('storage/'.$post->banner) }}" >
统计信息
- 总下载量: 69
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-01