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