Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
f9e3e873
Unverified
Commit
f9e3e873
authored
Nov 28, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let File implement the Responsable interface
which allows it being returned from a controller directly.
parent
6151aa74
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
3 deletions
+17
-3
File.php
Modules/Media/Entities/File.php
+17
-3
No files found.
Modules/Media/Entities/File.php
View file @
f9e3e873
...
...
@@ -3,6 +3,7 @@
namespace
Modules\Media\Entities
;
use
Dimsav\Translatable\Translatable
;
use
Illuminate\Contracts\Support\Responsable
;
use
Illuminate\Database\Eloquent\Model
;
use
Modules\Core\Traits\NamespacedEntity
;
use
Modules\Media\Helpers\FileHelper
;
...
...
@@ -16,7 +17,7 @@ use Modules\Tag\Traits\TaggableTrait;
* @package Modules\Media\Entities
* @property \Modules\Media\ValueObjects\MediaPath path
*/
class
File
extends
Model
implements
TaggableInterface
class
File
extends
Model
implements
TaggableInterface
,
Responsable
{
use
Translatable
,
NamespacedEntity
,
TaggableTrait
;
/**
...
...
@@ -43,7 +44,7 @@ class File extends Model implements TaggableInterface
'folder_id'
,
];
protected
$appends
=
[
'path_string'
,
'media_type'
];
protected
$casts
=
[
'is_folder'
=>
'boolean'
,
];
protected
$casts
=
[
'is_folder'
=>
'boolean'
,];
protected
static
$entityNamespace
=
'asgardcms/media'
;
public
function
parent_folder
()
...
...
@@ -66,7 +67,7 @@ class File extends Model implements TaggableInterface
return
FileHelper
::
getTypeByMimetype
(
$this
->
mimetype
);
}
public
function
isFolder
()
:
bool
public
function
isFolder
()
:
bool
{
return
$this
->
is_folder
;
}
...
...
@@ -84,4 +85,17 @@ class File extends Model implements TaggableInterface
return
false
;
}
/**
* Create an HTTP response that represents the object.
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public
function
toResponse
(
$request
)
{
return
response
()
->
file
(
public_path
(
$this
->
path
->
getRelativeUrl
()),
[
'Content-Type'
=>
$this
->
mimetype
,
]);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment