2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Database\Seeds;
|
|
|
|
|
|
|
|
use App\Abstracts\Model;
|
|
|
|
use App\Models\Common\Widget;
|
|
|
|
use App\Models\Common\Dashboard;
|
2019-12-31 02:20:10 +03:00
|
|
|
use App\Utilities\Widgets as WidgetUtility;
|
2019-11-16 10:21:14 +03:00
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
|
|
class Dashboards extends Seeder
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
Model::unguard();
|
|
|
|
|
|
|
|
$this->create();
|
|
|
|
|
|
|
|
Model::reguard();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function create()
|
|
|
|
{
|
|
|
|
$user_id = $this->command->argument('user');
|
|
|
|
$company_id = $this->command->argument('company');
|
|
|
|
|
2019-12-31 02:20:10 +03:00
|
|
|
$dashboard = Dashboard::create([
|
|
|
|
'company_id' => $company_id,
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'name' => trans('general.dashboard'),
|
|
|
|
'enabled' => 1,
|
|
|
|
]);
|
|
|
|
|
2020-01-04 21:53:10 +03:00
|
|
|
$widgets = WidgetUtility::getClasses(false);
|
2019-12-31 02:20:10 +03:00
|
|
|
|
|
|
|
$sort = 1;
|
|
|
|
|
|
|
|
foreach ($widgets as $class => $name) {
|
|
|
|
Widget::create([
|
2019-11-16 10:21:14 +03:00
|
|
|
'company_id' => $company_id,
|
2019-12-31 02:20:10 +03:00
|
|
|
'dashboard_id' => $dashboard->id,
|
|
|
|
'class' => $class,
|
|
|
|
'name' => $name,
|
|
|
|
'settings' => (new $class())->getDefaultSettings(),
|
|
|
|
'sort' => $sort,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$sort++;
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|