laravel drop foreign key if exists code example
Example 1: laravel remove foreign key
$table->dropForeign('posts_user_id_foreign');
Example 2: laravel check if primary key exists
$keyExists = DB::select(
DB::raw(
'SHOW KEYS
FROM your_table_name
WHERE Key_name=\'your_key_name\''
)
);