Skip to content

Commit

Permalink
Fix type check in UploadsImage trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Timot Tarjani committed Apr 12, 2024
1 parent 60ba485 commit 755c37d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/Controllers/Trait/UploadsImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Controllers\Trait;

use TypeError;
use Illuminate\Support\Facades\File;

trait UploadsImage {

Expand All @@ -14,18 +15,17 @@ private function getStrippedDirectoryPath($model){

public function uploadImage($model): bool {

if(in_array('HasImage', class_uses($model, true))){
if(!in_array('App\Model\Trait\HasImage', class_uses($model, true))){
throw new TypeError('Class['.get_class($model).'] does not use HasImage trait');
}

if (request()->hasFile($this->form_field_name)) {

\File::ensureDirectoryExists($this->getStrippedDirectoryPath($model));
File::ensureDirectoryExists($this->getStrippedDirectoryPath($model));
$img = request()->up_file->store($this->getStrippedDirectoryPath($model));
$model->attachImage($img);
if (extension_loaded('gd')) {

\File::ensureDirectoryExists($this->getStrippedDirectoryPath($model) . '/thumbs');
File::ensureDirectoryExists($this->getStrippedDirectoryPath($model) . '/thumbs');
\Intervention\Image\ImageManagerStatic::make(storage_path($img))->fit(300, 200)->save($model->getThumbnailDirectory(). DIRECTORY_SEPARATOR . $model->image);
}

Expand Down

0 comments on commit 755c37d

Please sign in to comment.