action = $action; $this->request = $request; $this->model = $leave; $this->function = Str::camel($action); $this->executeAction(); return $this->model; } public function store(Leave $leave, array $request) { $attributes = $request; $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $leave = $leave->create($attributes); return $leave; } public function update(Leave $leave, array $request) { $attributes = $request; $leave->update($attributes); return $leave; } public function destroy(Leave $leave, array $request) { $leave->delete(); return $leave; } public function copy(Leave $leave, array $request) { $count = $request['count'] ?: 1; if ($count == 1) { $leave = $leave->replicate(); $leave->created_at = Carbon::now(); $leave->save(); return $leave; } for ($i = 1; $i <= $count; $i++) { $new = $leave->replicate(); $new->created_at = Carbon::now(); $new->save(); } return $leave; } }