Modif url

This commit is contained in:
Cassandre Cantet 2017-10-04 16:46:56 +02:00
parent ece421c39c
commit e94ccf41d3
3 changed files with 19 additions and 10 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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'
]);
}