Answer the question
In order to leave comments, you need to log in
Laravel - Call to a member function hashName() on null?
When adding a record to the database, it is not possible to save the selected file from the form and get a link for writing to the database, what could be the problem?
route:
Route::post('/post', '[email protected]')->name('store');
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,4);
$path = Storage::putFile('public', $request->file('img'));
$url = Storage::url($path);
$post->img = $url;
$post->save();
return redirect()->route('home');
}
<form method="post" action="{{ route('store') }}">
@csrf
<div class="form-group"><input class="form-control" name="title" type="text"></div>
<div class="form-group"><textarea class="form-control" name="descr" type="text"></textarea></div>
<div class="form-group">
<input class="form-control" name="img" type="file">
</div>
<input type="submit" value="Создать пост" class="btn btn-primary" name="" id="">
</form>
Symfony\Component\Debug\Exception\FatalThrowableError
Call to a member function hashName() on null
C:\Users\User\Desktop\open server\OSPanel\domains\blog\vendor\laravel\framework\src\Illuminate\Filesystem\FilesystemAdapter.php:244
php artisan storage:link
made
Answer the question
In order to leave comments, you need to log in
Must be added to the form tag enctype="multipart/form-data"
Read more here
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question