/**
  * Update the project.
  * Set confirmed to 1.
  * @param $id
  * @return mixed
  */
 public function update($id)
 {
     $project = Project::find($id);
     $project->status = 'confirmed';
     $project->save();
     $message = $project->payer->name . ' has confirmed your project ' . $project->description . '!';
     //Create a notification in the database for the payee, in case they are not currently logged in
     $notification = new Notification(['message' => $message]);
     $notification->user()->associate($project->payee->id);
     $notification->save();
     //Pusher
     $pusher = new Pusher(env('PUSHER_PUBLIC_KEY'), env('PUSHER_SECRET_KEY'), env('PUSHER_APP_ID'));
     $data = ['payee_id' => $project->payee->id, 'notification' => $notification, 'project' => $project];
     $pusher->trigger('channel', 'confirmProject', $data);
     return $project;
 }
 /**
  * Stop the timer (update it).
  * Return all the projects,
  * as well as the project that is currently displaying in the project popup
  * @param Request $request
  * @return mixed
  */
 public function stopProjectTimer(Request $request)
 {
     // Fetch the required data
     $project = Project::find($request->get('project_id'));
     $last_timer_id = Timer::where('project_id', $project->id)->max('id');
     $timer = Timer::find($last_timer_id);
     // Update the data (Price will be zero if time is less than 30 seconds)
     $timer->finish = Carbon::now()->toDateTimeString();
     $timer->save();
     $timer->calculatePrice();
     $message = Auth::user()->name . ' has stopped the timer on the project ' . $project->description . '.';
     //Create a notification in the database for the payer, in case they are not currently logged in
     $notification = new Notification(['message' => $message]);
     $notification->user()->associate($project->payer->id);
     $notification->save();
     //Pusher
     $pusher = new Pusher(env('PUSHER_PUBLIC_KEY'), env('PUSHER_SECRET_KEY'), env('PUSHER_APP_ID'));
     $data = ['payer_id' => $project->payer_id, 'notification' => $notification];
     $pusher->trigger('channel', 'stopTimer', $data);
     // Create the fractal manager
     // @TODO: You could extract the next two lines to a ServiceProvider
     $fractal = new Manager();
     $fractal->setSerializer(new ArraySerializer());
     // Create an item with fractal
     $resource = new Item($timer, new StopProjectTimerTransformer());
     // $this->createItem(Model, transofrmer)
     // $this->createCollection(Model, transofrmer)
     // Send a response
     return response()->json($fractal->createData($resource)->toArray());
     //        return $this->responseOk($timer);
 }
Esempio n. 3
0
 public function newNotification()
 {
     $notification = new Models\Notification();
     $notification->user()->associate($this);
     return $notification;
 }