I am using laravel 5.4. I am facing a big problem from last few days in my app. Any error or success message is not showing properly. When I created those feature, those worked fine. All message was showing properly. But from last few days I am facing this issue. When I try to add some content, if validation fail then error message is not shows sometime and shows sometime. Same when validation is success. I can see those data stored in the database properly but success message is not shows all the time. Sometime shows.
Here is my from to create a notice
{!! 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() !!}
Here is method to create a notice
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();
}
Here Is my error message showing code
@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
Sorry for my poor english. Thanks in advance.