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