Compare commits
2 Commits
9f926f4ac5
...
7206bab9c2
Author | SHA1 | Date |
---|---|---|
aslan | 7206bab9c2 | |
aslan | 18df25c6a8 |
|
@ -46,9 +46,11 @@ class NewsController extends Controller
|
||||||
public function update(UpdateNewsRequest $request, News $news)
|
public function update(UpdateNewsRequest $request, News $news)
|
||||||
{
|
{
|
||||||
$validated = $request->validated();
|
$validated = $request->validated();
|
||||||
|
$urlPhoto = Storage::put('public', $request->file('photo'));
|
||||||
|
|
||||||
$news->name = $validated['name'];
|
$news->name = $validated['name'];
|
||||||
$news->text = $validated['text'];
|
$news->text = $validated['text'];
|
||||||
|
$news->photo = Storage::url($urlPhoto);
|
||||||
$news->save();
|
$news->save();
|
||||||
return redirect()->route('news.index');
|
return redirect()->route('news.index');
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ class UpdateNewsRequest extends FormRequest
|
||||||
return [
|
return [
|
||||||
'name' => 'required|string|max:255',
|
'name' => 'required|string|max:255',
|
||||||
'text' => 'string',
|
'text' => 'string',
|
||||||
|
'photo' => 'required|file',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,22 @@
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</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">
|
<div class="mt-3">
|
||||||
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
|
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -79,9 +79,10 @@ class NewsTest extends TestCase
|
||||||
|
|
||||||
public function testUpdateNews(): void
|
public function testUpdateNews(): void
|
||||||
{
|
{
|
||||||
|
$file = UploadedFile::fake()->create('fake.jpg', 100);
|
||||||
$response = $this->actingAs($this->user)
|
$response = $this->actingAs($this->user)
|
||||||
->withSession(['banned' => false])
|
->withSession(['banned' => false])
|
||||||
->patch(route('news.update', $this->news), $this->data);
|
->patch(route('news.update', $this->news), [...$this->data, 'photo' => $file]);
|
||||||
|
|
||||||
$response->assertRedirect(route('news.index'));
|
$response->assertRedirect(route('news.index'));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue