¨4.0.1¨
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Modules\Media\Entities;
|
||||
|
||||
use Modules\Media\IconResolver;
|
||||
use Modules\User\Entities\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\Media\Admin\MediaTable;
|
||||
use Modules\Support\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -24,6 +25,7 @@ class File extends Model
|
||||
*/
|
||||
protected $visible = ['id', 'filename', 'path'];
|
||||
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
@@ -36,6 +38,7 @@ class File extends Model
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the user that uploaded the file.
|
||||
*
|
||||
@@ -46,19 +49,22 @@ class File extends Model
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the file's path.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPathAttribute($path)
|
||||
{
|
||||
if (! is_null($path)) {
|
||||
if (!is_null($path)) {
|
||||
return Storage::disk($this->disk)->url($path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get file's real path.
|
||||
*
|
||||
@@ -66,11 +72,12 @@ class File extends Model
|
||||
*/
|
||||
public function realPath()
|
||||
{
|
||||
if (! is_null($this->attributes['path'])) {
|
||||
if (!is_null($this->attributes['path'])) {
|
||||
return Storage::disk($this->disk)->path($this->attributes['path']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if the file type is image.
|
||||
*
|
||||
@@ -81,6 +88,7 @@ class File extends Model
|
||||
return strtok($this->mime, '/') === 'image';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the file's icon.
|
||||
*
|
||||
@@ -91,15 +99,16 @@ class File extends Model
|
||||
return IconResolver::resolve($this->mime);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get table data for the resource
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function table($request)
|
||||
{
|
||||
$query = $this->newQuery()
|
||||
->when(! is_null($request->type) && $request->type !== 'null', function ($query) use ($request) {
|
||||
->when(!is_null($request->type) && $request->type !== 'null', function ($query) use ($request) {
|
||||
$query->where('mime', 'LIKE', "{$request->type}/%");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user