diff --git a/app/Http/Controllers/admin/DocumentController.php b/app/Http/Controllers/admin/DocumentController.php new file mode 100644 index 0000000..e17c202 --- /dev/null +++ b/app/Http/Controllers/admin/DocumentController.php @@ -0,0 +1,100 @@ +saveFile($request); + return redirect()->route('documents.index'); + } + + public function edit(Document $document) + { + $admissions = Admission::pluck('name', 'id'); + return view('admin.documents.edit', compact('admissions', 'document')); + } + + public function show(Document $document): View|Application|Factory|\Illuminate\Contracts\Foundation\Application + { + return view('admin.documents.show', compact('document')); + } + + public function update(UpdateDocumentRequest $request, Document $document): RedirectResponse + { + $validated = $request->validated(); + + $document->name = $validated['name']; + $document->description = $validated['description']; + $document->position = $validated['position']; + $document->admission_id = $validated['admission_id']; + $document->save(); + return redirect()->route('documents.index'); + } + + public function destroy(Document $document) + { + $document->delete(); + return redirect()->route('documents.index'); + } + + public function download($id) + { + $file = (new Document())->find($id); + return Storage::url($file->url); + } + public function createFromAdmission(Admission $admission): View + { + $admissions = Admission::pluck('name', 'id'); + $documents = Document::where('admission_id', '=', $admission->id)->get(); + return view('admin.documents.create_from_admission', compact('admissions', 'admission', 'documents')); + } + + public function storeFromAdmission(StoreDocumentRequest $request): RedirectResponse + { + $this->saveFile($request); + return redirect()->route('admissions.index'); + } + + private function saveFile(StoreDocumentRequest $request) + { + $fileName = $request->file('document')->getClientOriginalName(); + $name = Storage::put('public', $request->file('document')); + + $validated = $request->validated(); + + $document = new Document(); + $document->name = $validated['name']; + $document->description = $validated['description']; + $document->file_name = $fileName; + $document->url = Storage::url($name); + $document->position = $validated['position']; + $document->admission_id = $validated['admission_id']; + $document->save(); + } +} diff --git a/resources/views/admin/documents/create_from_admission.blade.php b/resources/views/admin/documents/create_from_admission.blade.php new file mode 100644 index 0000000..5a1430e --- /dev/null +++ b/resources/views/admin/documents/create_from_admission.blade.php @@ -0,0 +1,79 @@ +@extends('layouts.admin_layout') +@section('content') + @auth() +
+
+

Прикрепить файл

+ {{ Form::open(['url' => route('document_store_from_admission'), 'method' => 'POST', 'files'=>'true']) }} +
+ {{ Form::label('document', 'Путь к документу') }} +
+
+ {{ Form::file('document', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('document') }} + @endif +
+
+ {{ Form::label('name', 'Имя файла') }} +
+
+ {{ Form::text('name', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('name') }} + @endif +
+
+ {{ Form::label('description', 'Описание') }} +
+
+ {{ Form::text('description', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('description') }} + @endif +
+
+ {{ Form::label('position', 'Позиция') }} +
+
+ {{ Form::text('position', 0, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('name') }} + @endif +
+
+ {{ Form::label('admission_id', 'Пункт экрана приема') }} +
+
+ {{ Form::select('admission_id', $admissions, $admission->id, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('admission_id') }} + @endif +
+
+ {{ Form::submit('Загрузить файл', ['class' => 'btn btn-primary'])}} +
+ {{Form::close()}} +
+
+

Документы пункта {{ $admission->name }}

+ + +
+
+ @endauth +@endsection