baki / image
Store image
Installs: 43
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:package
Requires
- php: >=7.1.3
- illuminate/config: >=5.8.2
- illuminate/filesystem: >=5.8.2
- illuminate/http: >=5.8.2
- intervention/image: 2.5.1
This package is auto-updated.
Last update: 2024-04-29 03:51:19 UTC
README
Require this package with composer:
composer require baki/image
Usage
To use Image package, use this in your controller
use StoreImage;
After that, create your disk in config/filesystems.php
'yourDisk' => [
'driver' => 'local',
'root' => storage_path('app/public/your-directory'),
'url' => env('APP_URL').'/your-directory',
'visibility' => 'public',
],
Example
If you want to save your pictures (eg. for your News) and get the name of those pictures
Follow this command:
{{-- Input in laravel blade --}}
<input type="file" name="your_name_for_input">
$news->image = StoreImage::store('your_input_name', 'yourDisk', $request, 'default-pictures.jpg', false(for store), $news->old_image_from_database(enter if the previous parameter is true), 'width', 'height');
// Function to store your news and pictures
public function store(Request $r)
{
$input = new News;
// It is without crop image
$input->image = StoreImage::store('your_input_name', 'yourDisk', $request, 'default-pictures.jpg');
// It is with crop image
$input->image = StoreImage::store('your_input_name', 'yourDisk', $request, 'default-pictures.jpg', false, '', 100, 100);
$input->save();
return redirect()->route('news.index'); // This is my route. You can use your route.
}
If you want to edit your news. Old pictures will be delete, but default pictures will not be delete
Follow command:
$news->image = StoreImage::store('your_input_name', 'yourDisk', $request, 'default-pictures.jpg', true(for edit), $news->old_image_from_database(enter if the previous parameter is true), 'width', 'height');
// Function to update your news and pictures
public function update(Request $r, News $news)
{
// It is without crop image
$news->image = StoreImage::store('your_input_name', 'yourDisk', $request, 'default-pictures.jpg', true, $news->old_image_from_database);
// It is with crop image
$news->image = StoreImage::store('your_input_name', 'yourDisk', $request, 'default-pictures.jpg', true, $news->old_image_from_database, 'width', 'height');
$news->save();
return redirect()->route('news.index'); // It is my route. You can use your route.
}