Answer the question
In order to leave comments, you need to log in
How to upload images?
Hello, how is it possible to upload an image, here is the code I wrote
public function store(Request $request)
{
$this->validate($request,[
'title' => 'required',
'text' => 'required',
'date' => 'required',
]);
$status = Post::status($request->view);
if($request->hasFile('img')) {
$file = $request->file('img');
$input['img'] = $file->getClientOriginalName();
$file->move(public_path().'/upload',$input['img']);
}
Post::create([
'title' => $request->title,
'date' => $request->date,
'description' => $request->description,
'text' => $request->text,
'view' => $status,
'category_id' => $request->category_id,
]);
return redirect()->route('posts.index');
}
Answer the question
In order to leave comments, you need to log in
Get the image name or path and add the value to the property. You haven't added any information to the object about your file.
Saved to a folder, but how does the object know about it?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question