/**
  * Show the form for creating a new resource.
  * GET /rated/create
  *
  * @return Response
  */
 public function create()
 {
     $array = Input::all();
     $chance = Chance::find($array['chances_id']);
     //        dd($chance->userofchances[0]->users);
     if ($chance->vehicles->users->id == Auth::user()->id) {
         return View::make('rate.ratechance', compact('chance'));
     }
 }
 public function store()
 {
     $data = Input::all();
     $idchance = $data['chances_id'];
     $iduser = Auth::user()->id;
     $data['users_id'] = $iduser;
     $chance = Chance::find($idchance);
     $userofchances = UserofChance::where('chances_id', '=', $idchance)->where('users_id', '=', $iduser)->get();
     if (empty($userofchances)) {
         $message = json_encode(array('message', 'You have already taken this chance'));
         return $message;
     }
     $vehicle = Vehicle::find($chance->vehicles_id);
     if ($vehicle->users_id == $iduser) {
         $message = json_encode(array('message', 'You created this chance'));
     } else {
         UserofChance::create($data);
         $chance->capacity = $chance->capacity - 1;
         $chance->save();
         return Redirect::intended('/chanceslist/');
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $chance = Chance::find($id);
     return View::make('chances.showchance', compact('chance'));
 }