added all_news_view
This commit is contained in:
@@ -31,7 +31,7 @@ return new class extends Migration
|
||||
|
||||
// Настройка движка и кодировки (опционально, если нужно строго как в SQL)
|
||||
$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` ");
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user