<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class ClearTbl extends Command
{
protected $signature = 'command:delete-table {table_name}';
protected $description = 'Delete the data of table';
public function handle()
{
$tbl = $this->argument('table_name');
$check_tbl = Schema::hasTable($tbl);
if (!$check_tbl) {
echo "This table is not found";
return false;
}
DB::statement("DELETE FROM $tbl");
DB::statement("ALTER TABLE $tbl AUTO_INCREMENT=1");
echo "All rows has been Deleted !";
return false;
}
}
Comments
Post a Comment
If you any doubt of any topic then you can comment me.