The post created is to save the image and description to the DB but only the description gets saved.The request is being done via formData()..So currently trying via postman
$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
]);
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire