Compare commits

..

No commits in common. "7206bab9c2e7fd7df71e47b6f3039ee99a166a13" and "9f926f4ac5fe071af38cfa4e84ccd376952806be" have entirely different histories.

4 changed files with 1 additions and 21 deletions

View File

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

View File

@ -40,22 +40,6 @@
@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>

View File

@ -79,10 +79,9 @@ class NewsTest extends TestCase
public function testUpdateNews(): void
{
$file = UploadedFile::fake()->create('fake.jpg', 100);
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('news.update', $this->news), [...$this->data, 'photo' => $file]);
->patch(route('news.update', $this->news), $this->data);
$response->assertRedirect(route('news.index'));