lundi 29 octobre 2018

Why update picture doesn't detect file uploaded?

I am using laravel 5 to create an edit form for a profile and can update picture in the form.

I want to store a new image in edit form. I use this code in edit.blade to get the image by user.

  {!! Form::model($dataItemregistration,['method' => 'PATCH', 'action' => ['Modul\ProfilController@update', $dataItemregistration->ItemRegistrationID, 'files' => true] ]) !!}

  <div class="form-group">
            <div class="row">
                <div class="col-lg-3"> 
                  
                </div>
                <div class="col-lg-7">
                  {!! Form::file('gambar', array('class' => 'form-control')) !!}
                </div>
            </div>
        </div>
          <br>
      <div class="col-lg-10 text-center">
        {!! link_to(URL::previous(),'Back', ['class' => 'btn btn-warning btn-md']) !!}

        

        {!! Form::close() !!}

in controller update:

  public function update(Request $request, $id)
{
    $valueitemregistrations = Itemregistration::find($id);

     $this->validate($request,['gambar' => 'max:100000',
     ]);
     if ($request->hasFile('gambar')) {
    // Get the file from the request
    $file = $request->file('gambar');
    // Get the contents of the file
    $content = $file->openFile()->fread($file->getSize());

    $valueitemregistrations->Picture = $content;
    $valueitemregistrations->update();


        if($valueitemregistrations)
            return redirect('profil');
        else
            return redirect()->back()->withInput();
      } else { 
       echo "testing";
      }
     }

When I try to upload and update, it goes to echo "testing". It doesn't detected any files uploaded..

I had been using the same code for add.blade and it works.

Is it related to route path or else?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Q3xCMb
via IFTTT

Aucun commentaire:

Enregistrer un commentaire