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