Search code examples
laravelmongodbpoint

get point after submit Story


how to add points after submitting a post ?

This is my Controller :

public function store(PostRequest $request)
{
   $story = Auth::user()->post()->create($request->all());
   $image = $request->File('image');
   if ($image) {
       $image_name = time().'.'.$image->getClientOriginalExtension();
       $destinationPath = public_path('upload');
       $image->move($destinationPath, $image_name);

       $story->image = $image_name;
   }
   $story->update();
   if ($story) {
     flash()->success('Your Story Has Been successfully added');
   }
   return redirect()->back();
}

This is my table users :

protected $fillable = [
    'name', 'email', 'password', 'point'
];

This is my table post story :

 protected $fillable = [
     'user_id','title','description','image'

];


Solution

  • It is up to you to implement the logic of when you increment the point field but here is how you can.

    $story->increment('point');
    

    Or

    $story->point++;
    

    And of course $story->save();