2026_04_11_130000_create_responsibles_view.php 668 B

123456789101112131415161718192021222324252627
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Support\Facades\DB;
  4. return new class extends Migration
  5. {
  6. public function up(): void
  7. {
  8. DB::statement('DROP VIEW IF EXISTS responsibles_view');
  9. DB::statement(<<<'SQL'
  10. CREATE VIEW responsibles_view AS
  11. SELECT
  12. r.*,
  13. a.id AS area_id,
  14. a.name AS area_name
  15. FROM responsibles r
  16. LEFT JOIN areas a ON a.responsible_id = r.id AND a.deleted_at IS NULL
  17. SQL);
  18. }
  19. public function down(): void
  20. {
  21. DB::statement('DROP VIEW IF EXISTS responsibles_view');
  22. }
  23. };