/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, $project_id)
 {
     // get the project
     $project = Project::find($project_id);
     // validate
     // read more on validation at http://laravel.com/docs/validation
     $rules = ['position' => 'integer', 'image' => 'required|mimes:jpeg,png|max:10000'];
     $validator = Validator::make(Input::all(), $rules);
     // process the login
     if ($validator->fails()) {
         \Session::flash('message', 'We encountered the following errors:');
         \Session::flash('alert-class', 'alert-danger');
         return \Redirect::to('admin/project_images/' . $project->id . '/create')->withErrors($validator)->withInput(Input::except('password'));
     } else {
         // store
         $project_image = new Project_image();
         $project_image->project_id = $project->id;
         $project_image->position = Input::get('position');
         $project_image->image = Input::get('image');
         // image save to uploades folder
         if (Input::file('image')->isValid()) {
             $root = 'public/';
             $destinationPath = 'uploades/project_image/';
             // upload path
             $extension = Input::file('image')->getClientOriginalExtension();
             // getting image extension
             $filename = rand(11111, 99999) . '.' . $extension;
             // renameing image
             Input::file('image')->move($root . $destinationPath, $filename);
             // uploading file to given path
             // sending back with message
             // Session::flash('success', 'Upload successfully');
             $project_image->image = $destinationPath . $filename;
         }
         // end. image save to uploades folder
         $project_image->save();
         // redirect
         \Session::flash('message', 'Successfully created project_image!');
         return \Redirect::to('admin/project_images/' . $project->id);
     }
 }