public function store(Request $request)
{
$post = new post();
$post->title = $request->title;
$post->short_title = Str::length($request->title) > 30 ? Str::substr($request->title, 0, 30) . '...' : $request->title;
$post->descr = $request->descr;
$post->author_id = rand(1,10);
if ($request->file('img')) {
$path = Storage::putFile('public', $request->file('img'));
$url = Storage::url($path);
$post->img = $url;
}
$post->save();
return redirect()->route('index');
}
файл с формой:
<form action="{{route('store')}}" method="post" enctype="multipart/form-data">
@csrf
<h3>Создать пост</h3>
<div class="form-group">
<input type="text" class="form-control" name="title">
</div>
<div class="form-group">
<textarea name="descr" rows="3" class="form-control"></textarea>
</div>
<div class="form-group">
<input type="file">
</div>
<input type="submit" value="Создать пост" class="btn-outline-success">
</form>
web.php:
Route::get('/', 'postctr@index');
Route::get('index', 'postctr@index')->name('index');
Route::get('create', 'postctr@create')->name('create');
Route::post('/', 'postctr@store')->name('store');
вьюха ни в какой каталог не вложена
]]>