I want to create data but if the data already in database, it will update. but if the data not already in database, it will create new data.
this my controller
public function store(Request $request)
{
$real = SpentTime::findOrCreate([
'plan_id' => $request->get ('plan_id'),
'daily_spent_time' => $request->get ('daily_spent_time'),
'daily_percentage' => $request->get ('daily_percentage'),
'reason' => $request->get ('reason')
]);
return redirect()->route('real.index', compact( 'reals'));
}
this my model
public static function findOrCreate($plan_id)
{
$real = SpentTime::find($plan_id);
return $real ?: new SpentTime;
}
when I make data already in the database, the data is not updated.