【问题标题】:storing image in a existing table column and display it using laravel 4将图像存储在现有表列中并使用 laravel 4 显示它
【发布时间】:2015-04-15 05:14:27
【问题描述】:

我想将图像存储在现有表中。 我如何在 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>

【问题讨论】:

  • 欢迎来到 StackOverflow!查看您尝试过的代码将非常有帮助。当您edit your question 时,顶部有一个看起来像{ } 的按钮,用于帮助格式化代码。如果您做不到,请不要担心;有人可能会帮助您格式化它。未格式化的代码总比没有好。
  • 我现在附上了我的代码。所以如果你现在查看
  • @BasharNozibulla 是否要将图像的路径存储在数据库中?
  • @ffsantos92 是的,我想将图像的路径保存在数据库中。你能帮帮我吗?

标签: mysql laravel-4


【解决方案1】:

编辑商店功能如下

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

【讨论】:

    猜你喜欢
    • 2019-02-02
    • 2015-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-18
    • 1970-01-01
    • 2015-09-08
    相关资源
    最近更新 更多