对于许多应用程序,我的控制器:
public function store(Request $request)
{
$this->validate($request, ['title' => 'required',
'date' => 'required',
'image_1' => 'required|mimes:png,jpeg',
]);
$user = Auth::user()->id;
$report = new Report($request->all());
$report->author_id = $user;
$image = $request->file('image_1');
$destinationPath = 'uploads/reports';
$ext = $image->getClientOriginalExtension();
$fileName = rand(11111,99999).'.'.$ext;
$report->image_1 = $image->move($destinationPath, $fileName);
$report->save();
Session::flash('flash_message', 'Report added!');
return redirect('dash/reports');
}
我的创建视图是:
@extends('layouts.app')
@section('content')
<div class="container">
<h1>Crea un report</h1>
<p>I campi sono tutti obbligatori. In caso di difficoltà, fare riferimento ad <strong><a href="#">eloquent</a></strong> l'assistente virtuale.</p>
<hr/>
{!! Form::open(['url' => '/dash/reports', 'files' => true, 'class' => 'form-horizontal']) !!}
<div class="form-group {{ $errors->has('title') ? 'has-error' : ''}}">
{!! Form::label('fake', 'Nome e cognome', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
<input class="form-control" id="disabledInput" type="text" placeholder="{{ $author->name }} {{ $author->surname}}" disabled>
</div>
</div>
<div class="form-group {{ $errors->has('title') ? 'has-error' : ''}}">
{!! Form::label('title', 'Servizio', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::text('title', null, ['class' => 'form-control', 'required' => 'required']) !!}
{!! $errors->first('title', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('title') ? 'has-error' : ''}}">
{!! Form::label('date', 'Data', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::text('date', \Carbon\Carbon::now()->format('d/m/Y'), ['class' => 'form-control', 'required' => 'required']) !!}
{!! $errors->first('date', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('category_id') ? 'has-error' : ''}}">
{!! Form::label('category_id', 'Cliente', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::select('category_id', $category, null, ['class' => 'form-control'] ) !!}
{!! $errors->first('category_id', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('image_1') ? 'has-error' : ''}}">
{!! Form::label('image_1', 'Upload report cartaceo', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
<p>Solo immagini .jpg/.png</p>
{!! Form::file('image_1', null, ['class' => 'form-control', 'required' => 'required']) !!}
{!! $errors->first('image_1', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-3">
{!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!}
</div>
</div>
{!! Form::close() !!}
@if ($errors->any())
<ul class="alert alert-danger">
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
@endif
</div>
@endsection
现在,如果我提交一个有错误的表单,没有出现,为什么?此外,我的“会话闪存”不起作用,我只是使用apzzcoder / crud生成器,我只是按照指南。验证工作正常,但没有出现