我想将图像存储在现有表中。 我怎么能在laravel 4中这样做。我也想在我的网站上显示该图像。我试过它总是显示调用未定义的方法Symfony \ Component \ HttpFoundation \ File \ UploadedFile :: save()。
//my show blade
@extends ('layouts.default')
@section('content')
@foreach($posts as $post)
<div >
<div class="media col-md-8">
<a href="#" class="pull-left paddingTop ">
{{ HTML::image($post->image($destinationPath) }}
</a>
<div>
<h3><a href="#"><strong>{{$post->ad_title}}</strong></a><strong class="pull-right">{{ $post->price}} Tk</strong></h3>
</div>
<div>
<h5>{{ $post->description}}</h5>
</div>
</div>
</div>
@endforeach
@stop
这是我的表存储方法
public function store()
{
$post=new Post;
$post->user_id=Auth::id();
$post->category=Input::get('category');
$post->subcategory=Input::get('subcategory');
$post->add_type=Input::get('add_type');
$post->brand=Input::get('brand');
$post->screen_type=Input::get('screen_type');
$post->condition=Input::get('condition');
$post->ad_title=Input::get('ad_title');
$post->fuel=Input::get('fuel');
$post->transmission=Input::get('transmission');
$post->registration_year=Input::get('registration_year');
$post->engine_capacity=Input::get('engine_capacity');
$post->mileage=Input::get('mileage');
$post->description=Input::get('description');
$post->price=Input::get('price');
$post->mobile=Input::get('mobile');
$post->ad_title=Input::get('ad_title');
$post->image = Input::file('image');
//$post->image=Input::get('image');
$destinationPath = public_path() . '/images/';
$post->image->save($destinationPath);
$post->area=Input::get('area');
$post->save();
return 'your ad has been published :)';
}
我的图片输入表单
<div>{{ Form::file('image', ['class' => 'form-group']) }}</div>
答案 0 :(得分:0)
编辑商店功能,如下所示
public function store()
{
$post=new Post;
$post->user_id=Auth::id();
$post->category=Input::get('category');
$post->subcategory=Input::get('subcategory');
$post->add_type=Input::get('add_type');
$post->brand=Input::get('brand');
$post->screen_type=Input::get('screen_type');
$post->condition=Input::get('condition');
$post->ad_title=Input::get('ad_title');
$post->fuel=Input::get('fuel');
$post->transmission=Input::get('transmission');
$post->registration_year=Input::get('registration_year');
$post->engine_capacity=Input::get('engine_capacity');
$post->mileage=Input::get('mileage');
$post->description=Input::get('description');
$post->price=Input::get('price');
$post->mobile=Input::get('mobile');
$post->ad_title=Input::get('ad_title');
$name = Input::file('image')->getClientOriginalName();
Input::file('image')->move('public/images',$name);
$destinationPath = '/images/'.$name;
$post->image=$destinationPath;
$post->area=Input::get('area');
$post->save();
return 'your ad has been published :)';
}
并编辑刀片模板,如下所示
@extends ('layouts.default')
@section('content')
@foreach($posts as $post)
<div clss="row">
<div class="media col-lg-8">
<a href="#" class="pull-left paddingTop ">
{{ HTML::image($post->image) }}
</a>
<div>
<h3><a href="#"><strong>{{$post->ad_title}}</strong</a><strong
class="pull-right">{{ $post->price}} Tk</strong></h3>
</div>
<div>
<h5>{{ $post->description}}</h5>
</div>
</div>
</div>
@endforeach
<div class="">{{$posts->links()}}</div>
@stop