<?php namespace Bixo\Account\Actions; use Illuminate\Support\Carbon; use Illuminate\Support\Str; use Litepie\Actions\Concerns\AsAction; use Bixo\Account\Models\Acknowledgement; class AcknowledgementAction { use AsAction; protected $model; protected $namespace = 'bixo.account.acknowledgement'; protected $eventClass = \Bixo\Account\Events\AcknowledgementAction::class; protected $action; protected $function; protected $request; public function handle(string $action, Acknowledgement $acknowledgement, array $request = []) { $this->action = $action; $this->request = $request; $this->model = $acknowledgement; $this->function = Str::camel($action); $this->executeAction(); return $this->model; } public function store(Acknowledgement $acknowledgement, array $request) { $attributes = $request; $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $acknowledgement = $acknowledgement->create($attributes); return $acknowledgement; } public function update(Acknowledgement $acknowledgement, array $request) { $attributes = $request; $acknowledgement->update($attributes); return $acknowledgement; } public function destroy(Acknowledgement $acknowledgement, array $request) { $acknowledgement->delete(); return $acknowledgement; } public function copy(Acknowledgement $acknowledgement, array $request) { $count = $request['count'] ?: 1; if ($count == 1) { $acknowledgement = $acknowledgement->replicate(); $acknowledgement->created_at = Carbon::now(); $acknowledgement->save(); return $acknowledgement; } for ($i = 1; $i <= $count; $i++) { $new = $acknowledgement->replicate(); $new->created_at = Carbon::now(); $new->save(); } return $acknowledgement; } }