Add create and store functions to ImportController
MODIFY
app/Http/Controllers/ImportController.php
app/Http/Controllers/ImportController.php
namespace App\Http\Controllers;
+use App\Import;
use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Storage;
class ImportController extends Controller {
public function index() {
@@ -10,4 +12,26 @@ class ImportController extends Controller {
'imports' => session('space')->imports()->orderBy('created_at', 'DESC')->get()
]);
}
+
+ public function create() {
+ return view('imports.create');
+ }
+
+ public function store(Request $request) {
+ $request->validate([
+ 'name' => 'required|max:255',
+ 'file' => 'required' // TODO VALIDATE CSV
+ ]);
+
+ $path = $request->file('file')->store('imports');
+ $pathParts = explode('/', $path);
+
+ Import::create([
+ 'space_id' => session('space')->id,
+ 'name' => $request->input('name'),
+ 'file' => end($pathParts)
+ ]);
+
+ return redirect()->route('imports.index');
+ }
}

MODIFY
app/Import.php
app/Import.php
@@ -7,4 +7,6 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class Import extends Model {
use SoftDeletes;
+
+ protected $fillable = ['space_id', 'name', 'file'];
}

ADD
resources/views/imports/create.blade.php
+@extends('layout')
+
+@section('title', __('actions.create') . ' ' . __('models.import'))
+
+@section('body')
+ <div class="wrapper my-3">
+ <h2>{{ __('actions.create') }} {{ __('models.import') }}</h2>
+ <div class="box mt-3">
+ <form method="POST" action="/imports" enctype="multipart/form-data" autocomplete="off">
+ {{ csrf_field() }}
+ <div class="box__section">
+ <div class="input input--small">
+ <label>{{ __('fields.name') }}</label>
+ <input type="text" name="name" />
+ @include('partials.validation_error', ['payload' => 'name'])
+ </div>
+ <div class="input input--small mb-0">
+ <label>{{ __('fields.file') }}</label>
+ <input type="file" name="file" />
+ @include('partials.validation_error', ['payload' => 'file'])
+ </div>
+ </div>
+ <div class="box__section box__section--highlight row row--right">
+ <div class="row__column row__column--compact row__column--middle">
+ <a href="/imports">{{ __('actions.cancel') }}</a>
+ </div>
+ <div class="row__column row__column--compact ml-2">
+ <button class="button">{{ __('actions.create') }}</button>
+ </div>
+ </div>
+ </form>
+ </div>
+ </div>
+@endsection

MODIFY
resources/views/imports/index.blade.php
resources/views/imports/index.blade.php
@section('body')
<div class="wrapper my-3">
- <h2 class="mb-3">{{ __('models.imports') }}</h2>
+ <div class="row mb-3">
+ <div class="row__column row__column--middle">
+ <h2>{{ __('models.imports') }}</h2>
+ </div>
+ <div class="row__column row__column--compact row__column--middle">
+ <a href="/imports/create" class="button">{{ __('actions.create') }} {{ __('models.import') }}</a>
+ </div>
+ </div>
<div class="box">
@if (count($imports))
<div class="box__section box__section--header row">

MODIFY
routes/web.php
routes/web.php
@@ -43,7 +43,11 @@ Route::group(['middleware' => ['auth']], function () {
'destroy'
]);
- Route::resource('/imports', 'ImportController')->only(['index']);
+ Route::name('imports.')->group(function () {
+ Route::get('/imports', 'ImportController@index')->name('index');
+ Route::get('/imports/create', 'ImportController@create')->name('create');
+ Route::post('/imports', 'ImportController@store')->name('store');
+ });
Route::get('/settings', 'SettingsController@index')->name('settings');
Route::post('/settings', 'SettingsController@store');

Add create and store functions to ImportController