lundi 1 mai 2017

On Laravel I'm trying to update an image and It works, but when I decide not to add a new file I get this error: General error: 1364

I'm trying to update a table and it works perfectly but when I try to update whiteout changing the file it fails and gives me this error.

The error:

SQLSTATE[HY000]: General error: 1364 Field 'poster' doesn't have a default value (SQL: insert into patrocinadores (nombre, link, categoria, updated_at, created_at) values (Patrocinadores, http://ift.tt/2ppC6Sm, 3, 2017-05-01 23:44:44, 2017-05-01 23:44:44))

Here is my controller store()

public function store(Request $request){

    $this->validate(request(), [

        'nombre' => 'required',
        'link' => 'required',
        'poster' => 'image|image_size:<=1000',
        'categoria' =>'required',
    ]);

    $patrocinadores = new Patrocinadores;

    $patrocinadores->nombre = request('nombre');
    $patrocinadores->link = request('link');
    $newFoto=request()->file('poster');
    if($newFoto){
      $name=$newFoto. '.' . $newFoto->getClientOriginalExtension();
      $patrocinadores->poster = $newFoto->move('./uploads/', $name);
    }
    $patrocinadores->categoria = request('categoria');

    $patrocinadores->save();


    return redirect('/patrocinadores'); }

HTML:

  <div class="form-control-file">
    <label for="poster">Póster</label>

      <input type="file" class="form-control-file" id="poster" name="poster" aria-describedby="fileHelp"  accept="image/*" >

      <br>
      <div id="preview"><img src="" ></div>


    </div>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire