diff --git a/app/Http/Controllers/FileController.php b/app/Http/Controllers/FileController.php
new file mode 100644
index 0000000..00813aa
--- /dev/null
+++ b/app/Http/Controllers/FileController.php
@@ -0,0 +1,93 @@
+middleware('auth');
+ }
+ public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
+ {
+ abort_if(Auth::guest(), 403);
+
+ $files = File::all()->sortBy('position');
+ return view('files.index', compact('files'));
+ }
+
+ public function create($idReceptionScreen = null): View
+ {
+ abort_if(Auth::guest(), 403);
+
+ $receptionScreens = ReceptionScreen::pluck('name', 'id');
+ $idsReceptionScreens = $receptionScreens->keys()->toArray();
+ $files = File::where('reception_screen_id', '=', $idReceptionScreen)->get();
+ return view('files.create', compact('receptionScreens', 'idsReceptionScreens', 'idReceptionScreen', 'files'));
+ }
+
+ public function store(StoreFileRequest $request)
+ {
+ abort_if(Auth::guest(), 403);
+
+ $content = $request->file('url');
+ WorkWithFiles::saveFileToUploads($content);
+ $newPath = WorkWithFiles::renameFile($content);
+
+ $validated = $request->validated();
+ $file = new File();
+ $file->name = $validated['name'];
+ $file->url = $newPath;
+ $file->position = $validated['position'];
+ $file->reception_screen_id = $validated['idReceptionScreen'];
+ $file->save();
+ return redirect()->route('files.index');
+ }
+ public function edit(int $idFile)
+ {
+ abort_if(Auth::guest(), 403);
+
+ $file = (new File())->find($idFile);
+ $files = File::where('reception_screen_id', '=', $file->reception_screen_id)->get();
+
+ $receptionScreens = ReceptionScreen::pluck('name', 'id');
+ $idsReceptionScreens = $receptionScreens->keys()->toArray();
+ $idReceptionScreen = $file->reception_screen_id;
+ return view('files.edit', compact('receptionScreens', 'idsReceptionScreens', 'idReceptionScreen', 'files', 'file'));
+ }
+
+ public function update(UpdateFileRequest $request, File $file)
+ {
+ abort_if(Auth::guest(), 403);
+
+ $validated = $request->validated();
+
+ $file->name = $validated['name'];
+ $file->position = $validated['position'];
+ $file->reception_screen_id = $validated['idReceptionScreen'];
+ $file->save();
+ return redirect()->route('admin-reception-screen.index');
+ }
+
+ public function destroy($idFile)
+ {
+ abort_if(Auth::guest(), 403);
+
+ $file = (new File())->find($idFile);
+ $file->delete();
+ return redirect()->route('admin-reception-screen.index');
+ }
+}
diff --git a/app/Http/Controllers/ReceptionScreenController.php b/app/Http/Controllers/ReceptionScreenController.php
index 6edc843..a402db0 100644
--- a/app/Http/Controllers/ReceptionScreenController.php
+++ b/app/Http/Controllers/ReceptionScreenController.php
@@ -18,6 +18,8 @@ class ReceptionScreenController extends Controller
}
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
+ abort_if(Auth::guest(), 403);
+
$receptionScreens = ReceptionScreen::all()->sortBy('position');
return view('admin-reception-screen.index', compact('receptionScreens'));
}
@@ -32,6 +34,8 @@ class ReceptionScreenController extends Controller
public function store(StoreReceptionScreenRequest $request)
{
+ abort_if(Auth::guest(), 403);
+
$validated = $request->validated();
$receptionScreen = new ReceptionScreen();
$receptionScreen->name = $validated['name'];
@@ -52,6 +56,8 @@ class ReceptionScreenController extends Controller
public function update(UpdateReceptionScreenRequest $request, $id)
{
+ abort_if(Auth::guest(), 403);
+
$validated = $request->validated();
$receptionScreen = new ReceptionScreen();
$currentReceptionScreen = $receptionScreen->find($id);
diff --git a/app/Http/Controllers/UploadFileController.php b/app/Http/Controllers/UploadFileController.php
index 0dd8efa..7b74d46 100644
--- a/app/Http/Controllers/UploadFileController.php
+++ b/app/Http/Controllers/UploadFileController.php
@@ -6,10 +6,6 @@ use Illuminate\Http\Request;
class UploadFileController extends Controller
{
- public function index()
- {
- return view('uploadfile');
- }
public function showUploadFile(Request $request)
{
$file = $request->file('image');
diff --git a/app/Http/Requests/StoreFileRequest.php b/app/Http/Requests/StoreFileRequest.php
new file mode 100644
index 0000000..16494be
--- /dev/null
+++ b/app/Http/Requests/StoreFileRequest.php
@@ -0,0 +1,31 @@
+|string>
+ */
+ public function rules(): array
+ {
+ return [
+ 'name' => 'max:255',
+ 'position' => 'int|max:255',
+ 'url' => 'file',
+ 'idReceptionScreen' => 'int|max:255',
+ ];
+ }
+}
diff --git a/app/Http/Requests/UpdateFileRequest.php b/app/Http/Requests/UpdateFileRequest.php
new file mode 100644
index 0000000..a9854c0
--- /dev/null
+++ b/app/Http/Requests/UpdateFileRequest.php
@@ -0,0 +1,30 @@
+|string>
+ */
+ public function rules(): array
+ {
+ return [
+ 'name' => 'required|max:255',
+ 'position' => 'required||int|max:255',
+ 'idReceptionScreen' => 'int|max:255',
+ ];
+ }
+}
diff --git a/app/Services/WorkWithFiles.php b/app/Services/WorkWithFiles.php
new file mode 100644
index 0000000..92b87d1
--- /dev/null
+++ b/app/Services/WorkWithFiles.php
@@ -0,0 +1,29 @@
+move($destinationPath, $content->getClientOriginalName());
+ }
+
+ public static function renameFile($content)
+ {
+ $nameChunks = explode('.', $content->getClientOriginalName());
+ array_splice($nameChunks, 1);
+ $timestamp = Carbon::now();
+ $name = implode('.', $nameChunks);
+ $newName = "{$name}{$timestamp}.{$content->getClientOriginalExtension()}";
+
+ $dir = __DIR__;
+ $path = "{$dir}/../../public/uploads/";
+ $oldName = $content->getClientOriginalName();
+ rename("{$path}{$oldName}", "{$path}{$newName}");
+ return "{$path}{$newName}";
+ }
+}
diff --git a/resources/views/admin-reception-screen/index.blade.php b/resources/views/admin-reception-screen/index.blade.php
index 378847e..4c644e2 100644
--- a/resources/views/admin-reception-screen/index.blade.php
+++ b/resources/views/admin-reception-screen/index.blade.php
@@ -43,11 +43,11 @@
{{ $file->position }} |
{{ $file->name }} |
- редактировать
удалить
@@ -58,7 +58,7 @@
@endsection
diff --git a/resources/views/files/create.blade.php b/resources/views/files/create.blade.php
new file mode 100644
index 0000000..a9fafde
--- /dev/null
+++ b/resources/views/files/create.blade.php
@@ -0,0 +1,79 @@
+@extends('layouts.admin-layout')
+@section('content')
+ @auth()
+
+
+ Прикрепить файл
+ {{ Form::open(array('url' => route('files.store'), 'method' => 'POST', 'files'=>'true')) }}
+
+ {{ Form::label('url', 'Путь к файлу') }}
+
+
+ {{ Form::file('url', ['class' => 'form-control']) }}
+
+
+ @if ($errors->any())
+ {{ $errors->first('url') }}
+ @endif
+
+
+ {{ Form::label('name', 'Имя файла') }}
+
+
+ {{ Form::text('name', '', ['class' => 'form-control']) }}
+
+
+ @if ($errors->any())
+ {{ $errors->first('name') }}
+ @endif
+
+
+ {{ Form::label('position', 'Позиция') }}
+
+
+ {{ Form::text('position', 0, ['class' => 'form-control']) }}
+
+
+ @if ($errors->any())
+ {{ $errors->first('name') }}
+ @endif
+
+
+ {{ Form::label('idReceptionScreen', 'Пункт экрана приема') }}
+
+
+ {{ Form::select('idReceptionScreen', $receptionScreens, $idReceptionScreen, $idsReceptionScreens,['class' => 'form-select']) }}
+
+
+ @if ($errors->any())
+ {{ $errors->first('idReceptionScreen') }}
+ @endif
+
+
+ {{ Form::submit('Загрузить файл', ['class' => 'btn btn-primary'])}}
+
+ {{Form::close()}}
+
+ @if($idReceptionScreen !== null)
+
+ Файлы пункта Экрана Приема: {{ $receptionScreens[$idReceptionScreen] }}
+
+
+
+ Позиция |
+ Название |
+
+
+
+ @foreach($files as $file)
+
+ {{ $file->position }} |
+ {{ $file->name }} |
+ @endforeach
+
+
+
+ @endif
+
+ @endauth
+@endsection
diff --git a/resources/views/files/edit.blade.php b/resources/views/files/edit.blade.php
new file mode 100644
index 0000000..61564aa
--- /dev/null
+++ b/resources/views/files/edit.blade.php
@@ -0,0 +1,68 @@
+@extends('layouts.admin-layout')
+@section('content')
+ @auth()
+
+
+ Изменить файл
+ {{ Form::open(array('url' => route('files.update', $file), 'method' => 'PATCH', 'files'=>'true')) }}
+
+ {{ Form::label('name', 'Имя файла') }}
+
+
+ {{ Form::text('name', $file->name, ['class' => 'form-control']) }}
+
+
+ @if ($errors->any())
+ {{ $errors->first('name') }}
+ @endif
+
+
+ {{ Form::label('position', 'Позиция') }}
+
+
+ {{ Form::text('position', $file->position, ['class' => 'form-control']) }}
+
+
+ @if ($errors->any())
+ {{ $errors->first('name') }}
+ @endif
+
+
+ {{ Form::label('idReceptionScreen', 'Пункт экрана приема') }}
+
+
+ {{ Form::select('idReceptionScreen', $receptionScreens, $idReceptionScreen, $idsReceptionScreens,['class' => 'form-select']) }}
+
+
+ @if ($errors->any())
+ {{ $errors->first('idReceptionScreen') }}
+ @endif
+
+
+ {{ Form::submit('Загрузить файл', ['class' => 'btn btn-primary'])}}
+
+ {{Form::close()}}
+
+ @if($idReceptionScreen !== null)
+
+ Файлы пункта Экрана Приема: {{ $receptionScreens[$idReceptionScreen] }}
+
+
+
+ Позиция |
+ Название |
+
+
+
+ @foreach($files as $file)
+
+ {{ $file->position }} |
+ {{ $file->name }} |
+ @endforeach
+
+
+
+ @endif
+
+ @endauth
+@endsection
diff --git a/resources/views/files/index.blade.php b/resources/views/files/index.blade.php
new file mode 100644
index 0000000..3ad1ee5
--- /dev/null
+++ b/resources/views/files/index.blade.php
@@ -0,0 +1,36 @@
+@extends('layouts.admin-layout')
+@section('content')
+
+ Файлы
+
+ Добавить файл
+
+
+
+
+
+ Позиция |
+ Название файла |
+ Экран Приема |
+ действия |
+
+
+
+ @foreach($files as $file)
+
+ {{ $file->position }} |
+ {{ $file->name }} |
+ {{ $file->receptionScreen->name }} |
+ редактировать
+
+ удалить
+
+ |
+ @endforeach
+
+
+
+
+
+@endsection
diff --git a/routes/web.php b/routes/web.php
index ae771ca..3a7f161 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -1,5 +1,6 @@
name('home');
-Route::resources([
- '/users' => UserController::class,
- '/admin-reception-screen' => ReceptionScreenController::class
-]);
+Route::resource('/users', UserController::class)->middleware(['auth', 'verified']);
+Route::resource('/admin-reception-screen', ReceptionScreenController::class)->middleware(['auth', 'verified']);
+//Route::resource('/files', FileController::class)->middleware(['auth', 'verified']);
+Route::get('/files', [FileController::class, 'index'])->name('files.index');
+Route::post('/files', [FileController::class, 'store'])->name('files.store');
+Route::get('/files/create/{file?}', [FileController::class, 'create'])->name('files.create');
+Route::patch('/files/{file}', [FileController::class, 'update'])->name('files.update');
+Route::delete('files/{file}', [FileController::class, 'destroy'])->name('files.destroy');
+Route::get('/files/edit/{file}', [FileController::class, 'edit'])->name('files.edit');
Route::get('/course', function () {
return view('menu.course');
@@ -62,7 +68,6 @@ Route::get('/video-materials-for-applicants', function () {
return view('menu.abitur.videomaterialy-dlya-postupayushchikh');
})->name('videomaterialy-dlya-postupayushchikh');
-Route::post('/uploadfile', [UploadFileController::class, 'showUploadFile'])->name('uploadfile');
Route::get('/dashboard', function () {
return view('admin');
|