From 18df25c6a87e1588a52293b9ccfb8f8f740b13c6 Mon Sep 17 00:00:00 2001 From: aslan Date: Tue, 11 Jun 2024 10:37:39 +0300 Subject: [PATCH] fix edit picture news --- app/Http/Controllers/NewsController.php | 2 ++ app/Http/Requests/admin/UpdateNewsRequest.php | 1 + resources/views/admin/news/edit.blade.php | 16 ++++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/app/Http/Controllers/NewsController.php b/app/Http/Controllers/NewsController.php index 24437bb..5137fe9 100644 --- a/app/Http/Controllers/NewsController.php +++ b/app/Http/Controllers/NewsController.php @@ -46,9 +46,11 @@ class NewsController extends Controller public function update(UpdateNewsRequest $request, News $news) { $validated = $request->validated(); + $urlPhoto = Storage::put('public', $request->file('photo')); $news->name = $validated['name']; $news->text = $validated['text']; + $news->photo = Storage::url($urlPhoto); $news->save(); return redirect()->route('news.index'); } diff --git a/app/Http/Requests/admin/UpdateNewsRequest.php b/app/Http/Requests/admin/UpdateNewsRequest.php index e72b94f..8e6799f 100644 --- a/app/Http/Requests/admin/UpdateNewsRequest.php +++ b/app/Http/Requests/admin/UpdateNewsRequest.php @@ -16,6 +16,7 @@ class UpdateNewsRequest extends FormRequest return [ 'name' => 'required|string|max:255', 'text' => 'string', + 'photo' => 'required|file', ]; } } diff --git a/resources/views/admin/news/edit.blade.php b/resources/views/admin/news/edit.blade.php index 44a900e..e3ad44f 100644 --- a/resources/views/admin/news/edit.blade.php +++ b/resources/views/admin/news/edit.blade.php @@ -40,6 +40,22 @@ @endif +
+ {{ Form::label('photo', 'Путь к фото') }} + * +
+
+ {{ Form::file('photo', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.news.photo'), 'required']) }} +
+ Поле "Путь к фото" обязательно! +
+
+
+ @if ($errors->any()) + {{ $errors->first('photo') }} + @endif +
+
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}