【发布时间】:2018-08-21 12:35:58
【问题描述】:
我创建了一个注册表单。当有人尝试插入数据库中已经存在的日期、显示时间(st)和座位号(项目)时,我想显示一条消息,例如“您无法预订”。如果该数据不在数据库中,他可以插入它。然后我在 SeatsController.php 中创建了一个名为 seatinsert 的函数。但是,当我单击提交按钮时,没有任何反应。即使我找不到错误消息。
当我检查浏览器的控制台时,它显示了这一点。
http://localhost/FinalProject/public/seatsinsert500(内部服务器 错误)
XHR 加载失败:POST "http://localhost/FinalProject/public/seatsinsert"
在“网络”选项卡中 -> 响应向我显示了一条巨大的消息,即使我无法阅读。
Laravel 日志。
[2018-03-13 09:51:35] 生产。错误:没有应用程序加密密钥 已指定。 {“异常”:“[对象](运行时异常(代码:0): 未指定应用程序加密密钥。在 D:\wamp64\www\FinalProject\vendor\laravel\framework\src\Illuminate\Encryption\EncryptionServiceProvider.php:42) [堆栈跟踪]
我该如何解决这个问题??
这里是 Seats.blade.php
<form class="form-horizontal" id="form1" method="POST" action="{{ route('seatsinsert') }}" enctype="multipart/form-data">
{{ csrf_field() }}
<h4> <span id="success_message" class="text-success"></span> </h4>
<div class="form-group row">
<label for="example-date-input" class="col-2 col-form-label">Select Date :</label>
<div class="col-10">
<input class="form-control" type="date" name="date" placeholder="mm-dd-yyyy" id="example-date-input">
</div>
</div>
<div class="form-group">
<label for="exampleSelect1">Select Time :</label>
<select name="st" class="form-control" id="exampleSelect1">
<option>10.30 am</option>
</select>
</div>
<h2 style="font-size:1.2em;font-family: Times New Roman;"> Choose seats by clicking below seats :</h2>
<div id="holder">
<ul id="place">
</ul>
</div>
<div style="width:600px;text-align:center;overflow:auto"> <br>
</div>
<input type="submit" class="btn btn-primary" id="btnShowNew" value="Continue"> <br><br>
@if(session()->has('Msg'))
<h4 class="alert alert-success"> {{ session()->get('OnlyImg') }} </h4>
@endif
<br />
</center>
<script type="text/javascript">
$(function () {
$('#btnShowNew').click(function (e) {
e.preventDefault();
var items = [];
$.each($('#place li.' + settings.selectingSeatCss + ' a'), function (index, value) {
items.push($(this).attr('title'));
});
//console.log(items);
// $(location).attr('href', 'Seats');
$.ajax({
type: "post",
url: "{{ route('seatsinsert') }}",
data: {
_token: "{{ csrf_token() }}",
items: JSON.stringify(items),
date: $('input[name=date]').val(),
st: $('select[name=st]').val()},
success: function(data){
$("form").trigger("reset");
$('#success_message').fadeIn().html("Text");
}
});
}); //btnShowNew
}); //Final
这是我的 SeatsController.php
public function seatsinsert(Request $request)
{
$date = $request->input('date');
$st = $request->input('st');
$item = $request->input('items');
$items = str_replace(['[', ']', '"'], '', $item);
// Validation
$query = DB::table('seats')
->where('date', '=', $date)
->where('st', '=', $st)
->where('item', '=', $items)
->count();
dd($query);
if($query > 0 ) {
$request->session()->flash('Msg', 'No Seat');
return redirect('Seats');
}
else{
$user = new Seats();
$user->date = $date;
$user->st = $st;
$user->item = $items;
$user->save();
$request->session()->flash('Msg', 'OK Seat Inserted');
return redirect('Seats');
}
}
这是我的路由器。
Route::post('seatsinsert',[
'uses'=> 'SeatsController@seatsinsert',
'as' => 'seatsinsert'
]);
【问题讨论】:
-
检查您的日志文件以了解位于
storage/logs/laravel.log的最新错误。还将错误日志添加到问题中以帮助您更好 -
代码太多,我无法阅读,但您收到的是
500,这意味着服务器设置不正确或您的代码有错误;检查..../logs/laravel.log了解更多信息。祝你好运。 -
那个“巨大的消息”是laravel返回的页面,我猜它包含异常堆栈错误消息。您最好检查一下,因为它可能在堆栈消息的第一行中,您会在其中找到描述和违规行错误。
-
顺便说一句,您知道您看不到任何内容,因为您使用 ajax 发送帖子(并接收响应),对吧?
-
@VaibhavrajRoham - 我在问题中添加了日志。