Skip to content

Commit 1195c7a

Browse files
author
Julien Nahum
committed
Merge branch 'main' of https://github.com/JhumanJ/laravel-model-stats into main
2 parents 6d5c5bd + caa2526 commit 1195c7a

File tree

10 files changed

+19
-25
lines changed

10 files changed

+19
-25
lines changed

src/Http/Controllers/Controller.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@
99

1010
class Controller extends BaseController
1111
{
12-
use ValidatesRequests, AuthorizesRequests;
12+
use ValidatesRequests;
13+
use AuthorizesRequests;
1314

1415
public function success($data = [])
1516
{
1617
return response()->json(array_merge([
17-
'type' => 'success'
18+
'type' => 'success',
1819
], $data));
1920
}
2021

2122
public function error($data = [], $statusCode = 400)
2223
{
2324
return response()->json(array_merge([
24-
'type' => 'error'
25+
'type' => 'error',
2526
], $data), $statusCode);
2627
}
2728
}

src/Http/Controllers/DashboardController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ public function store(StoreRequest $request)
2626
public function update(Dashboard $dashboard, UpdateRequest $request)
2727
{
2828
$dashboard->update($request->validated());
29+
2930
return $dashboard;
3031
}
3132

32-
public function destroy(Dashboard $dashboard) {
33+
public function destroy(Dashboard $dashboard)
34+
{
3335
$dashboard->delete();
36+
3437
return $this->success([
35-
'message' => 'Dashboard deleted'
38+
'message' => 'Dashboard deleted',
3639
]);
3740
}
38-
3941
}

src/Http/Controllers/StatController.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
namespace Jhumanj\LaravelModelStats\Http\Controllers;
44

55
use Carbon\Carbon;
6-
use Illuminate\Container\Container;
7-
use Illuminate\Database\Eloquent\Model;
8-
use Illuminate\Support\Collection;
9-
use Illuminate\Support\Facades\File;
106
use Jhumanj\LaravelModelStats\Http\Requests\Widgets\DataRequest;
117
use Jhumanj\LaravelModelStats\Services\ModelStats;
128

@@ -18,7 +14,7 @@ public function widgetData(DataRequest $request)
1814
$dateFrom = Carbon::createFromFormat('Y-m-d', $request->date_from);
1915
$dateTo = Carbon::createFromFormat('Y-m-d', $request->date_to);
2016

21-
switch ($request->aggregate_type){
17+
switch ($request->aggregate_type) {
2218
case 'daily_count':
2319
return $modelStats->getDailyHistogram($dateFrom, $dateTo, $request->date_column);
2420
}

src/Http/Requests/Dashboard/StoreRequest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace Jhumanj\LaravelModelStats\Http\Requests\Dashboard;
55

6-
76
use Illuminate\Foundation\Http\FormRequest;
87

98
class StoreRequest extends FormRequest

src/Http/Requests/Dashboard/UpdateRequest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace Jhumanj\LaravelModelStats\Http\Requests\Dashboard;
55

6-
76
use Illuminate\Foundation\Http\FormRequest;
87

98
class UpdateRequest extends FormRequest

src/Http/Requests/Widgets/DataRequest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace Jhumanj\LaravelModelStats\Http\Requests\Widgets;
55

6-
76
use Illuminate\Container\Container;
87
use Illuminate\Database\Eloquent\Model;
98
use Illuminate\Foundation\Http\FormRequest;

src/LaravelModelStatsServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ protected function registerCommands()
7878
/**
7979
* Load the package's migrations
8080
*/
81-
protected function loadMigrations() {
81+
protected function loadMigrations()
82+
{
8283
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
8384
}
8485
}

src/Models/Dashboard.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ class Dashboard extends Model
1515
protected $fillable = [
1616
'name',
1717
'description',
18-
'body'
18+
'body',
1919
];
2020

2121
protected $casts = [
22-
'body' => 'array'
22+
'body' => 'array',
2323
];
2424
}

src/Services/ModelStats.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
namespace Jhumanj\LaravelModelStats\Services;
44

55
use Carbon\Carbon;
6-
use Illuminate\Database\Eloquent\Model;
76
use Illuminate\Support\Facades\DB;
87

98
class ModelStats
109
{
11-
1210
public $class;
1311

1412
public function __construct($class)
@@ -32,10 +30,10 @@ public function getDailyHistogram(
3230
});
3331
}
3432

35-
$data = $dataQuery->select(array(
33+
$data = $dataQuery->select([
3634
DB::raw('DATE('.$dateFieldName.') as date'),
37-
DB::raw('COUNT(*) as "count"')
38-
))->get()->pluck("count", "date");
35+
DB::raw('COUNT(*) as "count"'),
36+
])->get()->pluck("count", "date");
3937

4038
return self::fillMissingDays($data, $from, $to);
4139
}
@@ -49,11 +47,11 @@ public static function fillMissingDays($data, Carbon $since, Carbon $to, $defaul
4947

5048
foreach (array_reverse(range(0, $daysSince)) as $number) {
5149
$dateKey = Carbon::now()->subDays($number)->format('Y-m-d');
52-
if (!isset($data[$dateKey])) {
50+
if (! isset($data[$dateKey])) {
5351
$data[$dateKey] = $defaultValue;
5452
}
5553
}
54+
5655
return $data;
5756
}
58-
5957
}

tests/TestCase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
66
use Jhumanj\LaravelModelStats\LaravelModelStatsServiceProvider;
7-
use Jhumanj\LaravelModelStats\ModelStatsServiceProvider;
87
use Orchestra\Testbench\TestCase as Orchestra;
98

109
class TestCase extends Orchestra

0 commit comments

Comments
 (0)