2020-02-26 23:42:36 +00:00
< ? php
namespace App\Http\Controllers ;
use Illuminate\Support\Facades\Auth ;
use Illuminate\Support\Facades\DB ;
class RidecountController extends Controller
{
/**
* Create a new controller instance .
*
* @ return void
*/
public function __construct ()
{
$this -> middleware ([ 'auth' , 'verified' , '2fa' ]);
}
/**
* Show the application dashboard .
*
* @ param $attraction_id
* @ return \Illuminate\Contracts\Support\Renderable
*/
public function index ( $attraction_id )
{
$name = DB :: table ( 'attraction' ) -> select ( 'name' ) -> where ( 'id' , '=' , $attraction_id ) -> first () -> name ;
$top10 = DB :: table ( DB :: raw ( 'ridecount, (SELECT @row_number:=0) AS t' )) -> select ( 'uuid' , DB :: raw ( 'SUM(`count`) AS `count`' ), DB :: raw ( '(@row_number:=@row_number + 1) AS `num`' ))
-> where ( 'attractionId' , '=' , $attraction_id )
-> whereRaw ( 'YEARWEEK(date, 1) = YEARWEEK(CURDATE(), 1)' )
2021-06-27 19:01:43 +00:00
-> whereRaw ( 'YEAR(date) = YEAR(CURDATE())' )
2020-02-26 23:42:36 +00:00
-> groupBy ( 'uuid' )
-> orderByDesc ( 'count' )
-> take ( 10 ) -> get () -> all ();
$personal = DB :: table ( 'ridecount' )
-> where ( 'attractionId' , '=' , $attraction_id )
-> where ( 'uuid' , '=' , Auth :: user () -> uuid )
-> sum ( 'count' );
$total = DB :: table ( 'ridecount' )
-> where ( 'attractionId' , '=' , $attraction_id )
-> sum ( 'count' );
return view ( 'ridecount' ) -> with ([
'name' => $name ,
'top10' => $top10 ,
'personal' => $personal ,
'total' => $total
]);
}
}