Laravel 5中的图像不起作用

时间:2015-08-20 07:06:06

标签: php image laravel

我正在使用Laravel 5中的图像。我使用Laravel 5的民间传说包。它适用于商店但在更新图像时显示问题。

ArticleController:

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

Edit.blade.php:

<div class="form-group">
    <label><b>IMAGE</b></label>
    {!! Form::file('image_file',null,array('class'=>'form-control','id'=>'file_uploader')) !!}
    {!! Form::text('image',null,array('class'=>'form-control','id'=> 'file-name')) !!}
</div>

型号:

<?php namespace App;

use Illuminate\Database\Eloquent\Model;
use \App\Auth;

/**
 * Class Article
 * @package App
 */
class Article extends Model {

    /**
     * @var array
     */
    protected $guarded = [];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function tags()
    {
        return $this->belongsToMany('App\Tag');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function category()
    {
        return $this->belongsTo('App\Category');
    }
}

问题显示我在现场放置图像时..

Column not found: 1054 Unknown column 'image_file' in 'field list' 
(SQL: update `articles` set `updated_at` = 2015-08-20 07:15:14, 
`image_file` = afc-logo.gif where `id` = 457)

有人帮忙吗?

1 个答案:

答案 0 :(得分:0)

上述代码无效,因为在编辑表单中,encrypt/multipart不用于图片或任何文件。 所以我用file=true解决了我的问题..

{!! Form::model($article,['method' => 'PATCH','route'=> ['articles.update',$article->id],'files' => true]) !!}

这解决了整个更新图像问题......