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