我正在使用laravel 5.4。我的应用程序中的最近几天我遇到了一个大问题。任何错误或成功消息都无法正确显示。当我创建这些功能时,那些工作正常。所有消息都正确显示。但是从最近几天开始,我面临着这个问题。当我尝试添加一些内容时,如果验证失败,则错误消息有时会显示并显示某些时间。验证成功时也是如此。我可以正确地看到存储在数据库中的那些数据,但是不会一直显示成功消息。有时显示。
这是我来自创建通知
{!! Form::model($single_notice,['route'=>['notice.update',$single_notice->id],'method'=>'PUT','files'=>true]) !!}
<div class="col-lg-7">
<div style="display: block;" id="rulesformitem" class="formitem">
{{ Form::textarea('notice', null,array('class'=>'form-control notice-textarea')) }}
</div>
</div>
@if($single_notice->general == 'general')
<div class="col-lg-3 text-center" style="margin-top: 15px">
<label for="rules" id="ruleslabel">Notice For:</label>
<br>
<input onclick="document.getElementById('custom').disabled = true; document.getElementById('charstype').disabled = false;" type="radio" name="type" value="general" checked="checked">General
<br>
<input onclick="document.getElementById('custom').disabled = false; document.getElementById('charstype').disabled = true;" type="radio" name="type" >Demo/Final
<br>
<label for="rules" id="ruleslabel">Date & Time: <br> 01-01-2017 10(hr):30(m) <small>(This format)</small> </label>
<br>
<input type="datetime-local" class="form-control" name="demoOrfinal" id="custom" >
<br>
</div>
@else
<div class="col-lg-3 text-center" style="margin-top: 15px">
<label for="rules" id="ruleslabel">Notice For:</label>
<br>
<input onclick="document.getElementById('custom').disabled = true; document.getElementById('charstype').disabled = false;" type="radio" name="type" value="general">General
<br>
<input onclick="document.getElementById('custom').disabled = false; document.getElementById('charstype').disabled = true;" type="radio" name="type" checked="checked">Demo/Final
<br>
<label for="rules" id="ruleslabel">Date & Time: <br>
{{ Carbon\Carbon::parse($single_notice->demoOrfinal)->format('H:i d-m-Y') }}
</label>
<br>
<input type="datetime-local" class="form-control" name="demoOrfinal" id="custom" >
<br>
</div>
@endif
<div class="col-lg-2 text-center" style="margin-top: 20px">
<label>Upload File:</label>
@if($single_notice->image_link != 'null')
<input type="button" class="form-control" id="loadFileXml" value="Image" style="margin-bottom: 5px" onclick="document.getElementById('image').click();" />
{{ substr(strip_tags($single_notice->image_link),0,5) }}
{{ strlen(strip_tags($single_notice->image_link)) > 5 ? "...jpg" : "" }}
@endif
<input type="file" style="display:none;" id="image" name="notice_image"/>
<input type="button" class="form-control" id="loadFileXml" value="PDF" onclick="document.getElementById('pdf').click();" />
@if($single_notice->pdf_link != 'null')
<small>{{ substr(strip_tags($single_notice->pdf_link),0,5) }}
{{ strlen(strip_tags($single_notice->pdf_link)) > 5 ? "...pdf" : "" }}
</small>
@endif
<input type="file" style="display:none;" id="pdf" name="notice_pdf"/>
<button class="form-control btn-info" style="margin-top: 5px;">Update Notice</button>
{!! Form::close() !!}
以下是创建通知的方法
public function store(Request $request)
{
//dd($request);
$teacher_id = Auth::user()->id;
$this->validate($request,array(
'notice' => 'required|min:5',
'notice_image' => 'sometimes|mimes:jpeg,jpg,png',
'notice_pdf' => 'sometimes|mimes:pdf'
));
if($request->type == 'general')
{
$this->validate($request,array(
'type' => 'required',
));
}
if($request->type == 'on') {
$this->validate($request,array(
'demoOrfinal' => 'required|date',
));
}
$add_notice = new Notice;
$add_notice->notice = $request->notice;
$add_notice->general = $request->type;
$add_notice->demoOrfinal = $request->demoOrfinal;
$add_notice->posted_by = $teacher_id;
$add_notice->image_link = $request->notice_image;
$add_notice->pdf_link = $request->notice_pdf;
if ($request->hasFile('notice_image')) {
$file = $request->file('notice_image');
$filename = time().'.'.$file->getClientOriginalName();
$location = public_path('file/'.$filename);
Storage::put($filename,file_get_contents($file));
$add_notice->image_link = $filename;
}
if ($request->hasFile('notice_pdf')) {
$file = $request->file('notice_pdf');
$filename = time().'.'.$file->getClientOriginalName();
$location = public_path('file/'.$filename);
Storage::put($filename,file_get_contents($file));
$add_notice->pdf_link = $filename;
}
$add_notice->save();
Session::flash('success','Notice Has Been Posted. Thanks :-)');
return redirect()->back();
}
这是我的错误消息显示代码
@if(Session::has('success'))
<div class="alert alert-success">
<button type="button" class="close" data-dismiss="alert" aria-
hidden="true">×</button>
<strong>{{ Session::get('success') }}</strong>
</div>
@endif
@if(Session::has('denger-success'))
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert" aria-
hidden="true">×</button>
<strong>{{ Session::get('denger-success') }}</strong>
</div>
@endif
@if(count($errors))
<div class="alert alert-danger validation-error-message">
<button type="button" class="close" data-dismiss="alert" aria-
hidden="true">×</button>
<strong>Error:</strong>
<ul>
@foreach($errors->all() as $error)
<li>
{{ $error }}
</li>
@endforeach
</ul>
</div>
@endif
抱歉我的英语不好。 提前谢谢。
答案 0 :(得分:1)
当您运行php artisan session:table
和php artisan migrate
时,将.env文件更改为SESSION_DRIVER=database
,即可创建并使用“会话”表。
会话架构如下:
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->unique();
$table->text('payload');
$table->integer('user_id')->nullable();
$table->string('ip_address')->nullable();
$table->text('user_agent');
$table->integer('last_activity');
});
有效负载的文本太长,会话丢失。如果您'升级'到mediumtext,则可以解决问题。
您可以在数据库中执行此操作,也可以创建新的迁移php artisan make:migration change_payload_in_sessions_table
并添加:
Schema::table('sessions', function (Blueprint $table) {
$table->mediumText('payload')->change();
});
当然,您需要运行php artisan migrate