Answer the question
In order to leave comments, you need to log in
How to properly upload an image in Laravel?
I’ll write right away that I’m just learning Laravel and perhaps this question is ridiculous for Lara experts.
Now I am uploading a picture for a post
in the form for adding a post, added the upload input and enctype="multipart/form-data"
<div class="form-group">
<input type="file" name="img">
</div>
'title' => 'required|min:5|max:200|unique:blog_posts',
'slug' => 'max:200',
'excerpt'=> 'max:250',
'content_raw' => 'required|string|max:15000|min:3',
'category_id'=> 'required|integer|exists:blog_categories,id',
'img'=> 'required|image',
$data = $request->input();
$path = $request->file('img')->store('upload', 'public');
$data = array_add($data, 'img', $path);
dd($data);
public function store(BlogPostCreateRequest $request)
{
$data = $request->input();
$path = $request->file('img')->store('upload', 'public');
$data = array_add($data, 'img', $path);
$item = (new BlogPost())->create($data);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question