File: /var/www/ipsremont-demo/app/Models/Schema.php
<?php
namespace App\Models;
use App\Traits\My;
use App\Traits\Sortable;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* @property int $id
* @property string $external_id
* @property string $name
* @property string $photo
* @property string $sequence_number
* @property string $deleted_at
* @property string $created_at
* @property string $updated_at
*/
class Schema extends BaseModel
{
use SoftDeletes, Sortable, My;
protected $table = 'schema';
public static string $imagePath = '/demo-images/';
protected $fillable = [
'external_id',
'name',
'photo',
'sequence_number',
];
protected static $labels = [
'external_id' => 'schema.external_id',
'name' => 'schema.name',
'photo' => 'schema.photo',
'sequence_number' => 'schema.sequence_number',
];
public static function columns()
{
return [
"fields" => [
[
"displayName" => 'grid.external_id',
"field" => "external_id",
"sort" => true,
"sortType" => 'asc',
'class' => 'w-100px',
],
[
"displayName" => 'grid.name',
"field" => "name",
"sort" => true,
"sortType" => 'asc',
'class' => 'text-left',
],
[
"displayName" => 'grid.photo',
"field" => "photo",
"sort" => true,
"sortType" => 'asc',
'class' => 'text-left',
],
[
"displayName" => 'grid.sequence_number',
"field" => "sequence_number",
"sort" => true,
"sortType" => 'asc',
'class' => 'text-left',
],
[
"displayName" => '',
"field" => 'action',
"sort" => false,
'class' => 'w-100px',
],
],
"sortDefault" => [
[
"field" => 'sequence_number',
"sort" => 'asc',
],
],
];
}
public function getParts()
{
return Part::query()->select('parts.*')
->join('schema_parts', 'external_id', '=', 'part_external_id')
->where('schema_external_id', $this->external_id)
->get();
}
public function getName(): string
{
return $this->name;
}
public function getImage(): string
{
return empty($this->photo) ? '' : self::$imagePath . $this->photo;
}
}