%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/shaban/duassis/api/app/Models/
Upload File :
Create Path :
Current File : //var/www/html/shaban/duassis/api/app/Models/Utility.php

<?php

namespace App\Models;

use Spatie\Translatable\HasTranslations;

/**
 * @property integer id
 * @property string code
 * @property string name
 */

class Utility extends BaseModel
{
    use HasTranslations;

    public $translatable = [
        'name',
    ];

    protected $fillable = [
        'code',
        'name',
    ];

    protected $casts = [
        'id'    => 'integer',
        'code'  => 'string',
        'name'  => 'string',
    ];

    public static function createItem($data)
    {
        return self::query()->create($data);
    }

    public function removeUtility()
    {
        $fields = $this->fields();

        foreach ($fields as $field) {
            $field->utility()
                  ->dissociate();
            $field->save();
        }

        $this->load('fields');

        if ($this->fields()) {
            echo "Field still exits?";
        }
    }

    public function fields()
    {
        return $this->hasMany(Field::class);
    }

    public function updateItem(array $data)
    {
        $this->code = $data['code'];
        $this->name = $data['name'];
        $this->save();
        return $this;
    }

}

Zerion Mini Shell 1.0