コード例 #1
0
 /**
  * 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);
 }
コード例 #2
0
ファイル: routes.php プロジェクト: JennySwift/project-tracker
<?php

use App\Models\Payer;
use App\Models\Project;
use App\Models\Timer;
use App\User;
/**
 * Views
 */
Route::get('/test', function () {
    $timer = Timer::find(1);
    //dd($timer);
    return $timer;
});
//test
//Route::any('/test', function()
//{
//    $pusher = new Pusher(env('PUSHER_PUBLIC_KEY'), env('PUSHER_SECRET_KEY'), env('PUSHER_APP_ID'));
//
//    $channel = 'testChannel';
//    $event = 'testEvent';
//    $data = ['It works!'];
//
//    $pusher->trigger($channel, $event, $data);
//});
//Projects
//Route::get('projects', ['as' => 'projects', 'uses' => 'PagesController@index']);
Route::get('payee', ['as' => 'payee', 'uses' => 'PagesController@payee']);
Route::get('payer', ['as' => 'payer', 'uses' => 'PagesController@payer']);
//Credits
Route::get('/credits', function () {