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

تعليقات

المشاركات الشائعة من هذه المدونة

I am unable to figure out how to create payment collection request, after a form has been submitted in laravel

laravel, mysql transaction not working after failed one time