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
3c0a40ec
Commit
3c0a40ec
authored
Oct 27, 2014
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preparing the file move and db creation
parent
bb52701e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
0 deletions
+42
-0
MediaController.php
Http/Controllers/Api/MediaController.php
+22
-0
EloquentFileRepository.php
Repositories/Eloquent/EloquentFileRepository.php
+13
-0
FileRepository.php
Repositories/FileRepository.php
+7
-0
No files found.
Http/Controllers/Api/MediaController.php
View file @
3c0a40ec
<?php
namespace
Modules\Media\Http\Controllers\Api
;
use
Illuminate\Support\Str
;
use
Modules\Media\Http\Requests\UploadMediaRequest
;
use
Modules\Media\Repositories\FileRepository
;
class
MediaController
{
/**
* @var FileRepository
*/
private
$file
;
public
function
__construct
(
FileRepository
$file
)
{
$this
->
file
=
$file
;
}
/**
* Display a listing of the resource.
*
...
...
@@ -32,6 +44,16 @@ 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
);
// Return json response about those
dd
(
$request
->
file
(
'file'
));
}
...
...
Repositories/Eloquent/EloquentFileRepository.php
View file @
3c0a40ec
...
...
@@ -2,6 +2,7 @@
use
Modules\Core\Repositories\Eloquent\EloquentBaseRepository
;
use
Modules\Media\Repositories\FileRepository
;
use
Symfony\Component\HttpFoundation\File\UploadedFile
;
class
EloquentFileRepository
extends
EloquentBaseRepository
implements
FileRepository
{
...
...
@@ -14,4 +15,16 @@ class EloquentFileRepository extends EloquentBaseRepository implements FileRepos
public
function
update
(
$id
,
$data
)
{
}
/**
* Create a file row from the given file
* @param UploadedFile $file
* @return mixed
*/
public
function
createFromFile
(
UploadedFile
$file
)
{
$this
->
model
->
create
([
'filename'
=>
''
]);
}
}
Repositories/FileRepository.php
View file @
3c0a40ec
<?php
namespace
Modules\Media\Repositories
;
use
Modules\Core\Repositories\BaseRepository
;
use
Symfony\Component\HttpFoundation\File\UploadedFile
;
interface
FileRepository
extends
BaseRepository
{
/**
* Create a file row from the given file
* @param UploadedFile $file
* @return mixed
*/
public
function
createFromFile
(
UploadedFile
$file
);
}
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