20562

storing image in a existing table column and display it using laravel 4

Question:

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

this is my table storing method

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

my image input form

<div>{{ Form::file('image', ['class' => 'form-group']) }}</div>

Answer1:

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

Recommend

  • “stack level too deep” When Processing Carrierwave Image Versions in Nested Form
  • R Error - cannot change value of locked binding for 'df'
  • Compare a column between 2 csv files and write differences using Python
  • Create CSV file from c#: extra character in excel
  • AngularJS- How to pass data from one controller to another on ng-click()?
  • href inside href [duplicate]
  • BackgroundMediaPlayer set Uri source of Media library item
  • ResponseBuilder is not working when used with entity object
  • Is it possible to control programs with Javascript?
  • Dispose not working as expected in DirectorySearcher
  • Fluid video height
  • Weird LEFT OUTER JOIN on Includes eager loading of rails 3
  • Extract All Possible Paths from Expression-Tree and evaluate them to hold TRUE
  • XSLT foreach repeating nodes to flat
  • List images(01.png) and descriptions(01.txt) from directory
  • gspread or such: help me get cell coordinates (not value)
  • Webgrid not refreshing after delete MVC
  • azure media services - The request body is too large and exceeds the maximum permissible limit
  • D3 nodes and links from JSON with nested arrays of children
  • FileReader+canvas image loading problem
  • Insert into database using onclick function
  • Deselecting radio buttons while keeping the View Model in synch
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • DotNetZip - Calculate final zip size before calling Save(stream)
  • align graphs with different xlab
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • Load html files in TinyMce
  • Free memory of cv::Mat loaded using FileStorage API
  • Java static initializers and reflection
  • embed rChart in Markdown
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • unknown Exception android
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal