Insert data using database seeder in laravel
php artisan make:seeder AdminsTableSeeder
<?php
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class AdminsTableSeeder extends Seeder
{
public function run()
{
DB::table('admins')->insert([
'name' => 'admin',
'email' => 'admin@gmail.com',
'password' => Hash::make('password'),
]);
}
}
composer dump-autoload
Run seeder
php artisan db:seed --class=AdminsTableSeeder
********************************************
To insert multiple record
public function run()
{
DB::table('admins')->insert(array(
array(
'name' => "Steve",
'email' => 'steve@gmail.com',
'password' => Hash::make('secret'),
),
array(
'name' => "Laura",
'email' => 'laura@gmail.com',
'password' => Hash::make('secret'),
)
));
}
********************************************
Insert data using factory in laravel
php artisan make:factory AdminsTableSeeder
<?php
use Faker\Generator as Faker;
use App\Models\Admin;
use Illuminate\Support\Str;
use Hash;
$factory->define(Admin::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' =>$faker->email,
'password' => Hash::make('password'),
];
});
php artisan make:seeder AdminsTableSeeder
<?php
use Illuminate\Database\Seeder;
class AdminsTableSeeder extends Seeder
{
public function run()
{
factory(App\Models\Admin::class, 100)->create();
}
}
php artisan make:seeder AdminsTableSeeder
Subscribe to:
Post Comments (Atom)
Machine Learning - Potato Leaf Disease Prediction
Step 1: import numpy as np import pandas as pd import splitfolders import matplotlib.pyplot as plt import tensorflow as tf from tensorflow i...
-
Step1: composer create-project laravel/laravel canpac Step2: cd canpac Step3: composer require laravel/ui Step4: php artisan ui bootst...
-
1. Create a middleware name PostShortCodeMiddleware 2. Add this middleware in the kernal file. 3. Create a shortcode.php and shorcodeurl.php...
No comments:
Post a Comment