in my web application, people can create posts. Alonng with these posts, they may upload multiple images. To do this, I have a posts table and an image table. Posts hasMany images, and an Image belongs to a post. Therefore, the images table has an image_path column and a post_id column. My trouble is getting the post_id. Because I cant get a post ID before the post has been uploaded, I can't set which post the image belongs to. Anyway, here is some code:
public function create(){
$post = new Post;
$post->title=Input::get('title');
$post->body=Input::get('body');
$post->category=Input::get('category');
$post->save();
$images = Input::file('images');
foreach($images as $image) {
$destinationPath = 'public/uploads/';
$filename = $image->getClientOriginalName();
$image->move($destinationPath, $filename);
$id=Auth::id();
$file = new Image();
$file->image_path = 'uploads/' . $image->getClientOriginalName();
$file->description = '';
$file->post_id=Input::get('post_id');
$file->save();
}
What would be the best way to go about fixing this problem?
/posts/{id}/editafter the creation process. When you pre-create the posts Laravel would insertcreated_atandupdated_atcolumns by itself, and you can delete unneccessary posts let's say after a day or a week by listing the posts wherecreated_atandupdated_atcolumns are equal. By that you can use ajax calls to upload images by drag and drop usingjquery-file-uploaderwhich is pretty easy to implement or just doiddependent things.