I'm creating a web application that mimics a simple hotel booking system while also linking to a database. I have tables set up and the correct primary/foreign keys. When doing a dd to make sure I collected the data, the id keeps showing up as null, which I can't have.
I do have a foreign key set up in my reservations table to make sure they're linked when working with both of them since the customers.create form and the reservations.create form work with different tables. I've tried working with input types but I still get errors. I've spent a good day looking up what do to but I have not found anything that works yet.
My store function in my ReservationsController
public function store(Request $request)
{
$data =[
$request->customer_id,
$request->room_no,
$request->start_date,
$request->end_date,
$request->category,
];
dd($data);
}
My reservations table
public function up()
{
Schema::create('reservations', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('room_no')->unsigned();
$table->foreign('room_no')->references('room_no')->on('rooms');
$table->date('start_date');
$table->date('end_date');
$table->decimal('amount')->default(0.0);
$table->bigInteger('customer_id')->unsigned();
$table->foreign('customer_id')->references('id')->on('customers');
$table->string('category');
$table->timestamps();
});
My reservations.create.blade form
<form method="POST" action="/reservations/">
@csrf
<div>
<p>
<b>Enter Reservation for </b>
</p>
<h4 class="info-text">Select Room<br>
<select name="room_no" id="room_no">
<option value=100>100</option>
//...there are more but no need to post ALL of them here
</select>
</h4>
<h4 class="info-text">Select Room Type<br>
<select name="category" id="category">
<option value="Deluxe">Deluxe</option>
// shortened for question's sake again
</h4>
<p>
<b>Enter Start and End Date:</b>
</p>
<table>
<tr>
<td>
<input class="input" type="date" name="start_date" size="11" />
<input class="input" type="date" name="end_date" size="11" />
</td>
</tr>
</table>
<b>Cost of Stay</b>
<td>
<input class="input" type="decimal" name="amount" size="11"/>
</td>
<p><button type="submit">Create Reservation</button></p>
</div>
</form>
I am able to link my views with my routes
Route::resource('reservations', 'ReservationsController');
Route::get('/reservations/create/{customer_id}',
"ReservationsController@create_reservation");
When I dd in my controller, I should be getting all my data, including the customer_id, but when I run the application I get all my inputs except customer_id, which in this case is 0 in the array.
array:5 [▼
0 => null
1 => "106"
2 => "2019-04-16"
3 => "2019-04-30"
4 => "Economy"
]
I'm sorry if I got too wordy or I posted too much code. I'm still kind of new to all of this. All and any help of any kind is appreciated, thank you.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire