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