gpt4 book ai didi

mysql - 将图像存储在现有表列中并使用 laravel 4 显示它

转载 作者:行者123 更新时间:2023-11-30 22:48:17 25 4
gpt4 key购买 nike

我想将图像存储在现有表中。我怎么能在 laravel 4 中做到这一点。我也想在我的网站上显示该图像。我如何尝试它总是显示 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>

最佳答案

像下面这样编辑商店功能

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

然后像下面这样编辑 Blade 模板

@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

关于mysql - 将图像存储在现有表列中并使用 laravel 4 显示它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28906118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com