Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

paul_hub's avatar

Laravel imega not stornig in the public folder

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'));
}
0 likes
3 replies
tykus's avatar

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

paul_hub's avatar

@tykus this is my new function and notting

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',
    ]);

    $posts = new Post;
    $posts->title = $request->title;
    $posts->description = $request->description;
    $posts->body = $request->body;
    $posts->categories = $request->categories;
    $posts->date =  $request->date;

    if ($request->file('image')) {
        $file = $request->file('image');
        $filename = date('YmdHi') . $file->getClientOriginalName();
        $file->move(public_path('uploads'), $filename);
        $posts['image'] = $filename;
    }

    $posts->save();
paul_hub's avatar

@tykus it save's well to the database but my public forlder is empty

Please or to participate in this conversation.