use Illuminate\Support\Facades\Schema; if (Schema::hasColumn('users', 'email')) { echo "The users table has an email column!"; } else { echo "The users table does not have an email column."; }
use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateProductsTable extends Migration { public function up() { Schema::create('products', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('name'); $table->text('description'); $table->timestamps(); }); if (Schema::hasColumn('products', 'image_url')) { echo "The products table has an image_url column!"; } else { echo "The products table does not have an image_url column."; } } public function down() { Schema::dropIfExists('products'); } }In this example, we use the `Illuminate\Support\Facades\Schema` namespace to access the `Schema` class. We also use the `Illuminate\Database\Schema\Blueprint` and `Illuminate\Database\Migrations\Migration` namespaces to create and migrate a `products` table. The `up` method creates the `products` table with four columns: `id`, `name`, `description`, and `timestamps`. It also checks if the `products` table has an `image_url` column using the `hasColumn` method. The `down` method drops the `products` table if it exists. This code example also uses the Laravel package library.