Маршруты
Route::post('/review','RentalController@review');
Контроллер
public function review(Request $request)
{
$review = new Reviews();
$rpId = rand();
$review->rvid=$rpId;
$review->usid_fk = Auth::user()->uid;
// $propId= $request->input('propId');
$review->prId_fk = $request->input('propId');
$review->comment = $request->input('comment');
$review->rating = $request->input('rating');
$review->date = Carbon::now();
$review->save();
}
Файл миграции
public function up()
{
Schema::create('review', function (Blueprint $table) {
$table->integer('rvId')->primary();
$table->integer('usId_fk');
$table->foreign('usId_fk')->references('uid')->on('users');
$table->integer('prId_fk');
$table->foreign('prId_fk')->references('pId')->on('properties');
$table->date('date');
$table->integer('rating');
$table->string('comment');
});
}
Представление (шаблон Blade)
<form action="{{ url('/review') }}" method="POST">
{{ csrf_field() }}
<div class="modal-body">
<input type="hidden" name="propid" value="{{ $prop->propid }}"/>
<input id="rating" name="rating" class="rating rating-loading" data-show-clear="false" data-min="0" data-max="5" data-step="1" value="0">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Comment</span>
</div>
<textarea name="comment" class="form-control" aria-label="Comment"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
И ошибка ошибки нарушения ограничения целостности.
prId_fk
не может быть нулевой целостностью нарушение ограничения
Я пытался это исправить уже пару дней. Я пытался переписать мой код снова и снова, но он не работал. Ваш ответ будет высоко оценен.
Спасибо!