Stup Image is a Package For Storing / Updating the Images, More Clear Codes and Upgrade Readability. Integrated with Intervention Image Library
- 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
Use the Stupable
trait in your controller or any class to handle image upload and storage.
use Daycode\StupImage\Stupable;
public function store(Request $request): RedirectResponse
{
User::create(... + [
'thumbnail' => $this->uploadFile($request->file('thumbnail'), 'images/thumbnail'),
]);
return redirect()->back()->with('success', 'User Successfully Created');
}
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');
}