mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-23 14:34:19 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Abstracts;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\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, DataTransferObject $object){
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user