%PDF- %PDF-
Direktori : /var/www/html/hrsys/api/app/Models/ |
Current File : /var/www/html/hrsys/api/app/Models/Client.php |
<?php namespace App\Models; use Illuminate\Support\Facades\DB; use Throwable; /** * @property integer id * @property string name * @property string address * @property string email * @property string phone * @property string vat_number */ class Client extends BaseModel { /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'address', 'email', 'phone', 'vat_number', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'id' => 'integer', 'name' => 'string', 'address' => 'string', 'email' => 'string', 'phone' => 'string', 'vat_number' => 'string', ]; /** * @param $data * @return Client * @throws Throwable */ public static function createItem($data) { try { DB::beginTransaction(); /** @var Client $client */ $client = self::query() ->create([ 'name' => $data['name'], 'address' => array_key_exists('address', $data) ? $data['address'] : null, 'email' => array_key_exists('email', $data) ? $data['email'] : null, 'phone' => array_key_exists('phone', $data) ? $data['phone'] : null, 'vat_number' => array_key_exists('vat_number', $data) ? $data['vat_number'] : null, ]); DB::commit(); return $client; } catch (Throwable $e) { DB::rollBack(); throw $e; } } /** * @param $data * @return Client * @throws Throwable */ public function updateItem($data) { try { /** @var Client $client */ $client = $this->update([ 'name' => array_key_exists('name', $data) ? $data['name'] : null, 'address' => array_key_exists('address', $data) ? $data['address'] : null, 'email' => array_key_exists('email', $data) ? $data['email'] : null, 'phone' => array_key_exists('phone', $data) ? $data['phone'] : null, 'vat_number' => array_key_exists('vat_number', $data) ? $data['vat_number'] : null, ]); return $client; } catch (Throwable $e) { throw $e; } } public function projects() { return $this->hasMany(Project::class); } }