overtrue / laravel-uploader
An upload component for Laravel.
Fund package maintenance!
overtrue
Installs: 56 957
Dependents: 2
Suggesters: 0
Security: 0
Stars: 135
Watchers: 8
Forks: 20
Open Issues: 1
Requires
- ext-json: *
- laravel/framework: ^9.0|^10.0|^11.0
Requires (Dev)
- brainmaestro/composer-git-hooks: dev-master
- laravel/pint: ^1.5
- mockery/mockery: ^1.5
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-11-08 21:39:14 UTC
README
🌴 An upload component for Laravel.
Installing
-
Install package:
$ composer require overtrue/laravel-uploader -vvv
and publish the assets using command:
$ php artisan vendor:publish --provider=Overtrue\\LaravelUploader\\UploadServiceProvider
-
Routing
You can register routes in
routes/web.php
or other routes file:\LaravelUploader::routes(); // custom \LaravelUploader::routes([ 'as' => 'files.upload', 'middleware' => ['auth'], //... ]);
Usage
Custom controller
If you want to handle file upload, you can do it as simple as:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Routing\Controller as BaseController; use Overtrue\LaravelUploader\StrategyResolver; class MyUploadController extends BaseController { public function upload(Request $request) { return StrategyResolver::resolveFromRequest($request, $request->get('strategy', 'default'))->upload(); } }
Custom Response
If you want update the response, you can get key information from the return value object and return a new response:
public function upload(Request $request) { $response = StrategyResolver::resolveFromRequest($request, $request->get('strategy', 'default'))->upload(); return response()->json([ 'status' => 'success', 'url' => $response->url, 'origin_name' => $response->originalName, //... ]); }
You can get all these public properties:
int $size; string $path; string $mime; string $url; string $relativeUrl; string $filename; string $originalName; \Illuminate\Http\UploadedFile $file; \Overtrue\LaravelUploader\Strategy $strategy;
Recommend clients
❤️ Sponsor me
如果你喜欢我的项目并想支持它,点击这里 ❤️
Project supported by JetBrains
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
PHP 扩展包开发
想知道如何从零开始构建 PHP 扩展包?
请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》
License
MIT