Timmy28's avatar

Storing multiple images with eloquent

View blade:

{!! Form::open(array('route' => 'posts.store', 'data-parsley-validate' => '', 'files' => true)) !!}

{{ Form::label('featured_img', 'Upload Images') }}

{{ Form::file('featured_img',array('class' => 'form-control')) }}

{{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}

{!! Form::close() !!}

public function store(Request $request) {

    $this->validate($request, array(
            'title'         => 'required|max:255'
        ));

    $post = new Post;

    $post->title = $request->title;
    $post->body = $request->body;

    if ($request->hasFile('featured_img')) {
      $image = $request->file('featured_img');
      $filename = time() . '.' . $image->getClientOriginalExtension();
      $location = public_path('images/upload/' . $filename);
      Image::make($image)->save($location);

      $post->image = $filename;
    }

    $post->save();

    Session::flash('success', 'The blog post was successfully save!');

    return redirect()->route('posts.show', $post->id);
}

How to change the above code? instead of storing one image in same table I want to store multiple images in another table with eloquent. Other table has name uploads and is connected to post Model with eloquent belongsTo.

0 likes
0 replies

Please or to participate in this conversation.