mirror of
https://gitlab.com/omair-personal/exchange.git
synced 2026-08-19 04:24:08 +00:00
input data inside database using seeder
This commit is contained in:
+1
-2
@@ -7,6 +7,5 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Booking extends Model
|
||||
{
|
||||
// protected $guarded = [];
|
||||
// TODO : add term, amount, rate_id (FK), user_id (FK)
|
||||
protected $fillable = ['account_name', 'account_num', 'bank_name', 'bank_branch', 'company_name', 'company_address', 'bank_address', 'swift_code', 'cnap' ];
|
||||
protected $fillable = ['term', 'amount', 'rate_id', 'user_id', 'account_name', 'account_num', 'bank_name', 'bank_branch', 'company_name', 'company_address', 'bank_address', 'swift_code', 'cnap' ];
|
||||
}
|
||||
|
||||
@@ -36,23 +36,38 @@ class BookingController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$rates = Rate::find(1);
|
||||
$rates = Rate::all()->last();
|
||||
$term = $request->input('term');
|
||||
$rate = 1;
|
||||
|
||||
switch($term){
|
||||
case "x1_cash":
|
||||
case "x1_cash":
|
||||
$rate = $rates->x1_cash;
|
||||
break;
|
||||
break;
|
||||
case "x1_cheque":
|
||||
$rate = $rates->x1_cheque;
|
||||
break;
|
||||
case "x1_ba":
|
||||
$rate = $rates->x1_ba;
|
||||
break;
|
||||
case "x2_cash":
|
||||
$rate = $rates->x2_cash;
|
||||
break;
|
||||
case "x2_cheque":
|
||||
$rate = $rates->x2_cheque;
|
||||
break;
|
||||
case "x2_ba":
|
||||
$rate = $rates->x2_ba;
|
||||
break;
|
||||
default:
|
||||
$rate = "no";
|
||||
break;
|
||||
}
|
||||
return $rate;
|
||||
|
||||
|
||||
// return false;
|
||||
//$booking = Booking::create($request->all());
|
||||
//return response()->json($booking, 201);
|
||||
// return response()->json($booking, 201);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+9
-1
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -1,10 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Laravel - A PHP Framework For Web Artisans.
|
||||
* Laravel - A PHP Framework For Web Artisans
|
||||
*
|
||||
* @package Laravel
|
||||
* @author Taylor Otwell <taylor@laravel.com>
|
||||
*/
|
||||
|
||||
$uri = urldecode(
|
||||
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user