本文介绍了将图像存储在现有表列中并使用laravel 4显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将图像存储在现有表中.我该如何在laravel 4中做到这一点.我也想在我的网站中显示该图像.我如何尝试始终显示对未定义方法Symfony \ Component \ HttpFoundation \ File \ UploadedFile :: save()的调用.
I would like to store image in a existing table.How can i do that in laravel 4 .I also want to display that image in my website.How i tried it always shows Call to undefined method 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>
推荐答案
编辑存储功能,如下所示
Edit store function like below
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 :)';
}
并如下所示编辑刀片模板
and edit blade template like below
@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
这篇关于将图像存储在现有表列中并使用laravel 4显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!