daycode / stup-images
Stup Images or Store Or Update Images is a Package For Storing / Updating the Images, More Clear Codes and Upgrade Readability
Installs: 361
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/daycode/stup-images
Requires
- intervention/image: 3.11.2
README
Stup Image is a Package For Storing / Updating the Images, More Clear Codes and Upgrade Readability. Integrated with Intervention Image Library
Installation Guide
- Install the package via Composer:
composer require daycode/stup-images
- Dump and optimize the autoloader:
composer dump-autoload && php artisan optimize:clear
- Link the storage directory:
php artisan storage:link
Usage Examples
Use the Stupable
trait in your controller or any class to handle image upload and storage.
use Daycode\StupImage\Stupable;
Store to Database Example
public function store(Request $request): RedirectResponse { User::create(... + [ 'thumbnail' => $this->uploadFile($request->file('thumbnail'), 'images/thumbnail'), ]); return redirect()->back()->with('success', 'User Successfully Created'); }
Update to Database Example
public function update(Request $request, $id): RedirectResponse { $user = User::findOrFail($id); $user->update(... + [ 'thumbnail' => !empty($request->thumbnail) ? $this->syncUploadFile($request->file('thumbnail'), $user->thumbnail, 'images/thumbnail') : $user->thumbnail, ]); return redirect()->back()->with('success', 'User Successfully Updated'); }