Commit 3c0a40ec authored by Nicolas Widart's avatar Nicolas Widart

Preparing the file move and db creation

parent bb52701e
<?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'));
}
......
......@@ -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' => ''
]);
}
}
<?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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment