public function postStatus() { $files = Input::file('files'); $in = Input::all(); $post = Post::create(['StudentID' => Auth::user()->StudentID, 'Message' => $in['message']])->id; foreach ($files as $file) { $rules = array('file' => 'required|mimes:png,jpeg,jpg'); $validator = Validator::make(array('file' => $file), $rules); if ($validator->passes()) { $id = Str::random(14); $destinationPath = 'uploads/status/' . Auth::user()->StudentID . '/'; $filename = $id . $file->getClientOriginalName(); $mime_type = $file->getMimeType(); $extension = $file->getClientOriginalExtension(); $upload_success = $file->move('public/' . $destinationPath, $filename); if ($upload_success) { PostImage::create(['StudentID' => Auth::user()->StudentID, 'post_id' => $post, 'image' => $destinationPath . $filename]); } } } return Redirect::to('/')->with('message', 'Successfully posted'); }