Modif url
This commit is contained in:
		| @@ -10,8 +10,11 @@ use Meoran\Images\Model\Image; | |||||||
| class ImagesController extends BaseController | class ImagesController extends BaseController | ||||||
| { | { | ||||||
|  |  | ||||||
|     public function get($template, $filename) |     public function get($filename, $template = null) | ||||||
|     { |     { | ||||||
|  |         if ($template === null) { | ||||||
|  |             $template = 'original'; | ||||||
|  |         } | ||||||
|         switch (strtolower($template)) { |         switch (strtolower($template)) { | ||||||
|             case 'original': |             case 'original': | ||||||
|                 return $this->getOriginal($filename); |                 return $this->getOriginal($filename); | ||||||
| @@ -25,7 +28,7 @@ class ImagesController extends BaseController | |||||||
|     public function upload(Request $request) |     public function upload(Request $request) | ||||||
|     { |     { | ||||||
|         $this->validate($request, [ |         $this->validate($request, [ | ||||||
|            'image' => 'required|file|image' |             'image' => 'required|file|image' | ||||||
|         ]); |         ]); | ||||||
|  |  | ||||||
|         $image = new Image(['content' => $request->file('image')]); |         $image = new Image(['content' => $request->file('image')]); | ||||||
| @@ -66,10 +69,10 @@ class ImagesController extends BaseController | |||||||
|  |  | ||||||
|         $lifetime = config('image.lifetime'); |         $lifetime = config('image.lifetime'); | ||||||
|         if (empty($lifetime)) { |         if (empty($lifetime)) { | ||||||
|             $content = $this->applyTemplate($template,$path)->encode(); |             $content = $this->applyTemplate($template, $path)->encode(); | ||||||
|         } else { |         } else { | ||||||
|             $content = app('image')->cache(function ($image) use ($template, $path) { |             $content = app('image')->cache(function ($image) use ($template, $path) { | ||||||
|                 $this->applyTemplate($template,$path,$image); |                 $this->applyTemplate($template, $path, $image); | ||||||
|                 return $image; |                 return $image; | ||||||
|             }, $lifetime); |             }, $lifetime); | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -5,9 +5,9 @@ namespace Meoran\Images\Model; | |||||||
| use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||||
| use Illuminate\Database\Eloquent\Relations\MorphToMany; | use Illuminate\Database\Eloquent\Relations\MorphToMany; | ||||||
| use Intervention\Image\Exception\NotReadableException; | use Intervention\Image\Exception\NotReadableException; | ||||||
|  | use Intervention\Image\Image as InterventionImage; | ||||||
| use Meoran\Images\Exception\InvalidContent; | use Meoran\Images\Exception\InvalidContent; | ||||||
| use Spatie\ImageOptimizer\OptimizerChain; | use Spatie\ImageOptimizer\OptimizerChain; | ||||||
| use \Intervention\Image\Image as InterventionImage; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Class Image |  * Class Image | ||||||
| @@ -34,7 +34,11 @@ class Image extends Model | |||||||
|  |  | ||||||
|     public function getUrlAttribute() |     public function getUrlAttribute() | ||||||
|     { |     { | ||||||
|         return app('url')->to('/' . config('image.route') . '/original/' . $this->filename); |         $route = config('image.route'); | ||||||
|  |         if (empty($route)) { | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  |         return app('url')->to('/' . $route . '/' . $this->filename); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     protected static function boot() |     protected static function boot() | ||||||
| @@ -101,7 +105,8 @@ class Image extends Model | |||||||
|         $this->attributes['filename'] = $value; |         $this->attributes['filename'] = $value; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public function fileExist() { |     public function fileExist() | ||||||
|  |     { | ||||||
|         return is_file($this->getPath()); |         return is_file($this->getPath()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -168,7 +173,8 @@ class Image extends Model | |||||||
|      * @param $relationName |      * @param $relationName | ||||||
|      * @return MorphToMany |      * @return MorphToMany | ||||||
|      */ |      */ | ||||||
|     public static function createRelation(Model $class, $relationName) { |     public static function createRelation(Model $class, $relationName) | ||||||
|  |     { | ||||||
|  |  | ||||||
|         $instance = $class->newRelatedInstance(self::class); |         $instance = $class->newRelatedInstance(self::class); | ||||||
|  |  | ||||||
| @@ -180,7 +186,7 @@ class Image extends Model | |||||||
|  |  | ||||||
|         $relation = new MorphToMany( |         $relation = new MorphToMany( | ||||||
|             $instance->newQuery(), $class, $name, $table, |             $instance->newQuery(), $class, $name, $table, | ||||||
|             $foreignKey, $relatedKey, $relationName , $inverse |             $foreignKey, $relatedKey, $relationName, $inverse | ||||||
|         ); |         ); | ||||||
|         $relation->withPivot('position'); |         $relation->withPivot('position'); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -35,7 +35,7 @@ class ImagesServiceProvider extends ServiceProvider | |||||||
|             'as' => 'uploadImage', 'uses' => '\Meoran\Images\Http\Controllers\ImagesController@upload' |             'as' => 'uploadImage', 'uses' => '\Meoran\Images\Http\Controllers\ImagesController@upload' | ||||||
|         ]); |         ]); | ||||||
|  |  | ||||||
|         $this->app->get('images/{template}/{filename}', [ |         $this->app->get('images/{filename}[/{template}]', [ | ||||||
|             'as' => 'getPicture', 'uses' => '\Meoran\Images\Http\Controllers\ImagesController@get' |             'as' => 'getPicture', 'uses' => '\Meoran\Images\Http\Controllers\ImagesController@get' | ||||||
|         ]); |         ]); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user