add SlideFactory to Slide model and update DatabaseSeeder to include SlideSeeder for improved data seeding
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Data\Factories;
|
||||
|
||||
use App\Containers\Widget\Models\Slide;
|
||||
use App\Ship\Abstracts\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \App\Ship\Abstracts\Factories\Factory<\App\Ship\Models\Model>
|
||||
*/
|
||||
class SlideFactory extends Factory
|
||||
{
|
||||
|
||||
protected $model = Slide::class;
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'title' => $this->faker->sentence(3),
|
||||
'content' => $this->faker->paragraph(2),
|
||||
'image' => json_encode([
|
||||
'url' => '/public/img/thumbnail-1.png',
|
||||
'shading' => $this->faker->randomFloat(1, 0, 1)
|
||||
]),
|
||||
'link' => '/news/' . $this->faker->slug,
|
||||
'settings' => json_encode([
|
||||
'text_position' => $this->faker->randomElement(['center', 'left', 'right']),
|
||||
'link_text' => $this->faker->word,
|
||||
]),
|
||||
'color_theme' => $this->faker->safeColorName,
|
||||
'is_active' => $this->faker->boolean(80), // 80% шанс, что будет true
|
||||
'start_time' => $this->faker->dateTimeBetween('-1 week', '+1 week'),
|
||||
'end_time' => $this->faker->dateTimeBetween('+1 week', '+2 weeks'),
|
||||
'sort' => $this->faker->numberBetween(1, 10),
|
||||
// slider_id будет установлен в сидере
|
||||
'slidable_id' => null,
|
||||
'slidable_type' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Data\Seeders;
|
||||
|
||||
use App\Containers\Widget\Models\Slide;
|
||||
use App\Containers\Widget\Models\Slider;
|
||||
use App\Ship\Abstracts\Seeders\Seeder;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
|
||||
class SlideSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$slider = Slider::first();
|
||||
|
||||
if (!$slider) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Удаляем старые слайды перед созданием новых
|
||||
Slide::where('slider_id', $slider->id)->delete();
|
||||
|
||||
// Создаем 5 случайных слайдов, используя фабрику
|
||||
Slide::factory()
|
||||
->count(5)
|
||||
->for($slider) // Устанавливаем связь с родительской моделью Slider
|
||||
->create(); }
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Containers\Widget\Models;
|
||||
|
||||
use App\Containers\Widget\Data\Factories\SlideFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -26,4 +27,9 @@ class Slide extends Model
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
protected static function newFactory()
|
||||
{
|
||||
return SlideFactory::new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ship\Seeders;
|
||||
|
||||
use App\Containers\Widget\Models\ContactWidget;
|
||||
use App\Ship\Abstracts\Seeders\Seeder;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
|
||||
class ContactWidgetSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
|
||||
$data = [
|
||||
'id' => 1,
|
||||
'title' => 'Главная страница контакты',
|
||||
'slug' => 'glavnaia-stranica-kontakty',
|
||||
'content' => [
|
||||
[
|
||||
"title" => "Контакты",
|
||||
"items" => [
|
||||
[
|
||||
"header" => "Главный корпус",
|
||||
"details" => [
|
||||
[
|
||||
"content" => "622031, Свердловская обл. Нижний Тагил ул. Красногвардейская, 57",
|
||||
"url" => null
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
"header" => "Свяжитесь с нами",
|
||||
"details" => [
|
||||
[
|
||||
"content" => "(3435) 25-48-00",
|
||||
"url" => null
|
||||
],
|
||||
[
|
||||
"content" => "office@ntspi.ru",
|
||||
"url" => null
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
"title" => "Приемная комиссия",
|
||||
"items" => [
|
||||
[
|
||||
"header" => "Расписание",
|
||||
"details" => [
|
||||
[
|
||||
"content" => "Понедельник - Пятница с 08.30 до 17.00",
|
||||
"url" => null
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
"title" => "Полезное",
|
||||
"items" => [
|
||||
[
|
||||
"header" => "Главный корпус",
|
||||
"details" => [
|
||||
[
|
||||
"content" => "Виртуальный тур",
|
||||
"url" => "https://ntspi.ru/panorama/tour.html"
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
"header" => "Корпус ФХО",
|
||||
"details" => [
|
||||
[
|
||||
"content" => "Проспект Мира, 25",
|
||||
"url" => null
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'is_active' => 1,
|
||||
'created_at' => '2025-01-09 12:50:17',
|
||||
'updated_at' => '2025-05-20 09:18:46',
|
||||
];
|
||||
|
||||
ContactWidget::create($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ship\Seeders;
|
||||
|
||||
use App\Containers\Widget\Models\PageReferenceList;
|
||||
use App\Ship\Abstracts\Seeders\Seeder;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
|
||||
class PageReferenceListSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$data = [
|
||||
'id' => 1,
|
||||
'title' => 'Главная страница ресурс',
|
||||
'slug' => 'glavnaia-stranica-resurs',
|
||||
'content' => array(
|
||||
['model_select' => null, 'title' => 'Система Moodle НТГСПИ', 'image' => [], 'icon' => 'heroicon-o-academic-cap', 'link' => 'https://do.ntspi.ru/', 'link_text' => 'Перейти'],
|
||||
['model_select' => null, 'title' => 'ЭИОС', 'image' => [], 'icon' => 'heroicon-o-computer-desktop', 'link' => 'https://eios.rsvpu.ru/', 'link_text' => 'Перейти'],
|
||||
['model_select' => 'Custom', 'title' => 'Группа Вконтакте', 'image' => [], 'icon' => 'heroicon-c-user-group', 'link' => 'https://vk.com/ntspi', 'link_text' => 'Читать', 'content' => null],
|
||||
['model_select' => 'Custom', 'title' => 'Книга почёта', 'image' => [], 'link' => 'http://book.ntspi.ru/', 'link_text' => 'Смотреть', 'content' => null, 'icon' => 'heroicon-o-book-open'],
|
||||
['model_select' => 'Custom', 'title' => 'Поступление в ВУЗ онлайн', 'image' => [], 'link' => 'https://minobrnauki.gov.ru/press-center/news/novosti-ministerstva/50667/', 'link_text' => 'Читать', 'content' => null, 'icon' => 'heroicon-o-globe-alt'],
|
||||
['model_select' => 'Custom', 'title' => 'Интернет олимпиады', 'image' => [], 'link' => 'https://olymp.i-exam.ru/', 'link_text' => 'Читать', 'content' => null, 'icon' => 'heroicon-o-cursor-arrow-rays'],
|
||||
['model_select' => 'Custom', 'title' => 'РЕЕСТР рекомендуемых образовательных цифровых сервисов для использования в программах подготовки педагогических кадров', 'image' => [], 'link' => 'https://new.ntspi.ru/storage/files/reestr.pdf', 'link_text' => 'Смотреть', 'content' => null, 'icon' => 'heroicon-o-table-cells']
|
||||
),
|
||||
'is_active' => 1,
|
||||
'created_at' => '2025-01-09 09:37:27',
|
||||
'updated_at' => '2025-05-23 18:57:38',
|
||||
];
|
||||
|
||||
PageReferenceList::create($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ship\Seeders;
|
||||
|
||||
use App\Containers\Widget\Models\Slider;
|
||||
use App\Ship\Abstracts\Seeders\Seeder;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
|
||||
class SliderSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Slider::create([
|
||||
'id' => 1,
|
||||
'title' => 'quos-velit-quisquam',
|
||||
'slug' => 'quos-velit-quisquam',
|
||||
'is_active' => 1,
|
||||
'created_at' => '2025-04-02 22:08:34',
|
||||
'updated_at' => '2025-04-02 22:08:34',
|
||||
]); }
|
||||
}
|
||||
Reference in New Issue
Block a user