input data inside database using seeder

This commit is contained in:
Mohd Arief
2018-05-17 15:13:29 +08:00
parent 204af7cf5e
commit 18d2ba4543
8 changed files with 103 additions and 11 deletions
@@ -23,7 +23,14 @@ class CreateBookingsTable extends Migration
$table->string('company_address');
$table->string('bank_address');
$table->string('swift_code');
$table->string('cnap');
$table->string('cnap');
$table->string('term');
$table->double('amount');
$table->unsignedInteger('rate_id');
$table->foreign('rate_id')
->references('id')->on('rates')
->onDelete('cascade');
$table->timestamps();
});
}
@@ -36,5 +43,6 @@ class CreateBookingsTable extends Migration
public function down()
{
Schema::dropIfExists('bookings');
}
}
@@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ChangeUserIdInBookingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('bookings', function (Blueprint $table) {
$table->unsignedInteger('user_id');
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}
+19 -1
View File
@@ -1,6 +1,7 @@
<?php
use Illuminate\Database\Seeder;
use Carbon\Carbon;
class BookTableSeeder extends Seeder
{
@@ -11,6 +12,23 @@ class BookTableSeeder extends Seeder
*/
public function run()
{
//
DB::table('bookings')->insert([
// 'id' => '1',
'account_name' => 'kazim',
'account_num' => '1234',
'bank_name' => 'maybank',
'bank_branch' => 'rembau',
'company_name' => 'ICEF',
'company_address' => 'selangor',
'bank_address' => 'cyber',
'swift_code' => 'qwe123',
'cnap' => '123asd',
'term' => 'x1',
'amount' => 1.2,
'rate_id' => '1',
'user_id' => '17',
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
'updated_at' => Carbon::now()->format('Y-m-d H:i:s'),
]);
}
}
+3 -1
View File
@@ -13,7 +13,9 @@ class DatabaseSeeder extends Seeder
{
$this->call(UsersTableSeeder::class);
$this->call(RolesAndPermissionsSeeder::class);
$this->call(RateTableSeeder::class);
// $this->call(RateTableSeeder::class);
$this->call('Database\Seeds\RateTableSeeder');
$this->call('Database\Seeds\BookTableSeeder');
}
}
+14
View File
@@ -1,6 +1,7 @@
<?php
use Illuminate\Database\Seeder;
use Carbon\Carbon;
class RateTableSeeder extends Seeder
{
@@ -18,6 +19,19 @@ class RateTableSeeder extends Seeder
'x2_cash' => 1.2,
'x2_cheque' => 1.2,
'x2_ba' => 1.2,
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
'updated_at' => Carbon::now()->format('Y-m-d H:i:s'),
]);
DB::table('rates')->insert([
'x1_cash' => 1.3,
'x1_cheque' => 1.3,
'x1_ba' => 1.3,
'x2_cash' => 1.3,
'x2_cheque' => 1.3,
'x2_ba' => 1.3,
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
'updated_at' => Carbon::now()->format('Y-m-d H:i:s'),
]);
}
}