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']) }}