mardi 27 octobre 2020

laravel post for image and textfield

The post created is to save the image and description to the DB but only the description gets saved.

    $post = new Post;
    $post->user_id = Auth::user()->id;
    $post->desc = $request->desc;

    //check if post has photo
   If($request->hasFile('image'){
    $imageName = time().'.'.$request->image->extension();  
    $request->image->move('storage/posts', $imageName);
        $post->photo = $imageName ;
    }
    //mistake
    $post->save();
    $post->user;
    return response()->json([
        'success' => true,
        'message' => 'posted',
        'post' => $post
    ]);
}


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3kxrLOs
via IFTTT

Aucun commentaire:

Enregistrer un commentaire