0

To much apporoaches, my controller:

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');
}

and my create view is:

@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

Now, if I submit a form with a error, nothing appear, why? Also, my "session flash" does not work, i just use the apzzcoder/crud generator, i just follow the guide. Validation work correctly, but nothing appear

user0111001101
  • 187
  • 2
  • 4
  • 11
  • 1
    $this->validate() returns back to previous page when the validation failed. That's why you session flash not firing. About other validation, what kind of form error did you tried? I'm sure didn't tried leaving title or date field empty because 'required' doesn't allows you to submit empty fields – Ravisha Hesh May 10 '16 at 18:11
  • Made a test here, with image field empty, and the errors are there in red. What's wrong exactly? – Felippe Duarte May 10 '16 at 18:15
  • with blank, nothing error, only for Form::text work html 'required' form validator. for image, nothing appear same if i put other format image (like .pdf), nothing appear – user0111001101 May 10 '16 at 18:16
  • possible for null attribute on my form? – user0111001101 May 10 '16 at 18:21
  • solved, is L 5.2 error, just follow this: http://stackoverflow.com/questions/34438463/laravel-5-2-errors-not-appearing-in-blade thank you man! – user0111001101 May 10 '16 at 18:37

0 Answers0