Files
shipping-portal/app/Classes/General/Abstracts/AbstractService.php
T
2021-06-17 20:12:08 +08:00

42 lines
901 B
PHP

<?php
namespace App\Classes\General\Abstracts;
use App\Classes\Exceptions\MalformedRequestException;
use App\Classes\General\Interfaces\DataTransferObject;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\QueryException;
abstract class AbstractService
{
/**
* @param Model $model
* @param DataTransferObject $object
* @return mixed
* @throws MalformedRequestException
*/
public function execute(Model $model){
try{
/** @var Model $model */
$model = $this->handler($model);
if($model->save()){
return $model;
}
} catch (QueryException $exception){
throw new MalformedRequestException('Unable to update the record due to unexpected error');
}
}
abstract function getModel(Model $model);
abstract function handler(Model $model);
}