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
63934248
Commit
63934248
authored
Oct 28, 2014
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Saving the file data
parent
36374ddb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
15 deletions
+20
-15
MediaController.php
Http/Controllers/Api/MediaController.php
+10
-14
EloquentFileRepository.php
Repositories/Eloquent/EloquentFileRepository.php
+10
-1
No files found.
Http/Controllers/Api/MediaController.php
View file @
63934248
<?php
namespace
Modules\Media\Http\Controllers\Api
;
use
Illuminate\Support\
Str
;
use
Illuminate\Support\
Facades\Response
;
use
Modules\Media\Http\Requests\UploadMediaRequest
;
use
Modules\Media\
Repositories\FileRepository
;
use
Modules\Media\
Services\FileService
;
class
MediaController
{
...
...
@@ -10,10 +10,14 @@ class MediaController
* @var FileRepository
*/
private
$file
;
/**
* @var FileService
*/
private
$fileService
;
public
function
__construct
(
File
Repository
$fil
e
)
public
function
__construct
(
File
Service
$fileServic
e
)
{
$this
->
file
=
$fil
e
;
$this
->
file
Service
=
$fileServic
e
;
}
/**
...
...
@@ -44,17 +48,9 @@ class MediaController
*/
public
function
store
(
UploadMediaRequest
$request
)
{
$file
=
$request
->
file
(
'file'
);
$fileName
=
Str
::
slug
(
$file
->
getClientOriginalName
());
// Move the uploaded file to /public/assets/media/
$file
->
move
(
public_path
()
.
'/assets/media'
,
$fileName
);
// Save the file info to db
$savedFile
=
$this
->
file
->
createFromFile
(
$file
);
$savedFile
=
$this
->
fileService
->
store
(
$request
->
file
(
'file'
));
// Return json response about those
dd
(
$request
->
file
(
'file'
));
return
Response
::
json
(
$savedFile
->
toArray
());
}
/**
...
...
Repositories/Eloquent/EloquentFileRepository.php
View file @
63934248
<?php
namespace
Modules\Media\Repositories\Eloquent
;
use
Modules\Core\Repositories\Eloquent\EloquentBaseRepository
;
use
Modules\Media\Helpers\FileHelper
;
use
Modules\Media\Repositories\FileRepository
;
use
Symfony\Component\HttpFoundation\File\UploadedFile
;
...
...
@@ -23,8 +24,16 @@ class EloquentFileRepository extends EloquentBaseRepository implements FileRepos
*/
public
function
createFromFile
(
UploadedFile
$file
)
{
$fileName
=
FileHelper
::
slug
(
$file
->
getClientOriginalName
());
$this
->
model
->
create
([
'filename'
=>
''
'filename'
=>
$fileName
,
'path'
=>
public_path
()
.
"/assets/media/
{
$fileName
}
"
,
'extension'
=>
$file
->
guessClientExtension
(),
'mimetype'
=>
$file
->
getClientMimeType
(),
'filesize'
=>
$file
->
getFileInfo
()
->
getSize
(),
]);
return
$this
->
model
;
}
}
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