Level 104
The public_path helper function already includes the public directory; also, the value stored in the database should be derived from the stored path, not from the Request
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
public function store(Request $request) { $posts = $request->validate([
'title' => ['required', 'min:5',],
'description' => ['required', 'min:5',],
'body' => ['required', 'min:5',],
'categories' => ['required', 'max:255'],
'date' => ['required'],
'image' => 'required|max:2048',
]);
if ($request->hasFile('image')) {
$image = $request->file('image');
$image_name = $image->getClientOriginalName();
$image->move(public_path('/public/uploads'), $image_name);
$image_path = "/public/uploads" . $image_name;
}
$posts = new Post;
$posts->title = $request->title;
$posts->description = $request->description;
$posts->body = $request->body;
$posts->categories = $request->categories;
$posts->date = $request->date;
$posts->image = $request->image;
$posts->save();
return redirect()->route('posts.post')->with('status', 'Post Created Successfully');
}
public function show()
{
$post = Post::all();
return view('posts.edit', compact('post'));
}
Please or to participate in this conversation.