<?php
use Illuminate\Database\Migrations\Migration;use Illuminate\Support\Facades\DB;
return new class extends Migration {public function up():void{$n=now();foreach(['serp_checks.view'=>'SERP kontrollerini görüntüleme','serp_checks.manage'=>'SERP kontrollerini yönetme'] as $name=>$label)DB::table('permissions')->insertOrIgnore(compact('name','label')+['created_at'=>$n,'updated_at'=>$n]);$r=DB::table('roles')->pluck('id','name');$p=DB::table('permissions')->whereIn('name',['serp_checks.view','serp_checks.manage'])->pluck('id','name');foreach(['super_admin','admin'] as $role)if(isset($r[$role]))foreach($p as $id)DB::table('permission_role')->insertOrIgnore(['role_id'=>$r[$role],'permission_id'=>$id,'created_at'=>$n,'updated_at'=>$n]);if(isset($r['support'],$p['serp_checks.view']))DB::table('permission_role')->insertOrIgnore(['role_id'=>$r['support'],'permission_id'=>$p['serp_checks.view'],'created_at'=>$n,'updated_at'=>$n]);}public function down():void{$ids=DB::table('permissions')->whereIn('name',['serp_checks.view','serp_checks.manage'])->pluck('id');DB::table('permission_role')->whereIn('permission_id',$ids)->delete();DB::table('permissions')->whereIn('id',$ids)->delete();}};