Make dashboard configurable.
This commit is contained in:
54
app/Models/Dashboard.php
Normal file
54
app/Models/Dashboard.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Dashboard extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'width',
|
||||
'height',
|
||||
'sort',
|
||||
'active',
|
||||
'settings'
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'title',
|
||||
];
|
||||
|
||||
public function getTitleAttribute()
|
||||
{
|
||||
return __('dashboard.title_' . $this->name);
|
||||
}
|
||||
|
||||
public static function toObject()
|
||||
{
|
||||
$all = self::orderBy('sort')->get();
|
||||
$tiles = new \stdClass();
|
||||
foreach ($all as $tile) {
|
||||
$key = $tile->name;
|
||||
$tiles->$key = $tile;
|
||||
}
|
||||
return $tiles;
|
||||
}
|
||||
|
||||
public static function activeToObject()
|
||||
{
|
||||
$all = self::where('active', true)->orderBy('sort')->get();
|
||||
$tiles = new \stdClass();
|
||||
foreach ($all as $tile) {
|
||||
$key = $tile->name;
|
||||
$tiles->$key = $tile;
|
||||
}
|
||||
return collect($tiles);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user