fix edit picture news

This commit is contained in:
aslan 2024-06-11 10:37:39 +03:00
parent 9f926f4ac5
commit 18df25c6a8
3 changed files with 19 additions and 0 deletions

View File

@ -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');
}

View File

@ -16,6 +16,7 @@ class UpdateNewsRequest extends FormRequest
return [
'name' => 'required|string|max:255',
'text' => 'string',
'photo' => 'required|file',
];
}
}

View File

@ -40,6 +40,22 @@
@endif
</div>
<div class="mt-2">
{{ Form::label('photo', 'Путь к фото') }}
<span class="text-danger">*</span>
</div>
<div class="mt-2">
{{ Form::file('photo', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.news.photo'), 'required']) }}
<div class="invalid-feedback">
Поле "Путь к фото" обязательно!
</div>
</div>
<div class="text-danger">
@if ($errors->any())
{{ $errors->first('photo') }}
@endif
</div>
<div class="mt-3">
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
</div>