added all_news_view
This commit is contained in:
@@ -6,6 +6,6 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
|
|
||||||
class News extends Model
|
class News extends Model
|
||||||
{
|
{
|
||||||
protected $table = 'allNewsView';
|
protected $table = 'news';
|
||||||
protected $primaryKey = 'id';
|
protected $primaryKey = 'id';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ return new class extends Migration
|
|||||||
|
|
||||||
// Настройка движка и кодировки (опционально, если нужно строго как в SQL)
|
// Настройка движка и кодировки (опционально, если нужно строго как в SQL)
|
||||||
$table->engine = 'InnoDB';
|
$table->engine = 'InnoDB';
|
||||||
$table->charset = 'utf8mb3';
|
// $table->charset = 'utf8mb3';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
// Сначала удаляем, если уже существует
|
||||||
|
DB::statement("DROP VIEW IF EXISTS `all_news_view` ");
|
||||||
|
|
||||||
|
// Создаем вьюху
|
||||||
|
DB::statement("
|
||||||
|
CREATE VIEW `all_news_view` AS
|
||||||
|
SELECT
|
||||||
|
`id`,
|
||||||
|
DATE_FORMAT(`date`, '%m') AS `month`,
|
||||||
|
DATE_FORMAT(`date`, '%d') AS `day`,
|
||||||
|
DATE_FORMAT(`date`, '%H:%i') AS `time`,
|
||||||
|
`header`,
|
||||||
|
`long_text` AS `article`,
|
||||||
|
`from_id` AS `author`,
|
||||||
|
`img_src`,
|
||||||
|
`author_type`,
|
||||||
|
`copy_post_id`,
|
||||||
|
`post_type`
|
||||||
|
FROM
|
||||||
|
`news`
|
||||||
|
WHERE
|
||||||
|
`long_text` <> ''
|
||||||
|
ORDER BY `date` DESC
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
DB::statement("DROP VIEW IF EXISTS `all_news_view` ");
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -24,6 +24,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
|
|
||||||
$this->call([
|
$this->call([
|
||||||
UserSeeder::class,
|
UserSeeder::class,
|
||||||
|
EventSeeder::class,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user