laravel seeder if code example
Example: laravel seeder check if table has data
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class UserSeeder extends Seeder
{
public function run()
{
// check if table is empty before seeding data
if(DB::table('users')->count() == 0) {
DB::table('users')->insert([
[
'first_name' => 'John',
'last_name' => 'Doe'
]
]);
}
}
}