jeudi 20 août 2015

i am working with image in laravel 5.i tried image update with other field but it is not working

i am working with image in laravel 5.I use folklore package of laravel 5.it works fine for store but shows problem while updating image. my code is like this:

$article_to_update = $article->find($id);
    $uploaded_image = $request->file('image_file');
    $parameter = $request->all();

    if (isset($uploaded_image)) {

        $ext = $uploaded_image->getClientOriginalExtension();
        $newImageName = $article_to_update->id . "." . $ext;

        $uploaded_image->move(
            base_path() . '/public/uploads/article/', $newImageName
        );
        Image::make(base_path() . '/public/uploads/article/' . $newImageName, array(
            'width' => 170,
            'height' => 120,
        ))->save(base_path() . '/public/uploads/article/' . $newImageName);
        $parameter = $request->all();
        $parameter['image'] = $newImageName;
          unset($parameter['image_file']);
        $article_to_update->update($parameter);

    } else {

        $article_to_update->update($parameter);
    }    


    Session::flash('message', 'The article was successfully edited!.');
    Session::flash('flash_type', 'alert-success');  
    return redirect('articles');

laravel php laravel 5 laravel 4 laravel with laravel tutorial

Aucun commentaire:

Enregistrer un commentaire