Skip to content

Support Laravel 12 #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
php: [8.4, 8.3, 8.2]
laravel: [11.x]
laravel: [12.x, 11.x]
stability: [prefer-lowest, prefer-stable]

name: Static Analysis - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }}
@@ -59,7 +59,7 @@ jobs:
fail-fast: false
matrix:
php: [8.4, 8.3, 8.2]
laravel: [11.x]
laravel: [12.x, 11.x]
stability: [prefer-lowest, prefer-stable]

name: Tests - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - MySQL 8.0
@@ -116,7 +116,7 @@ jobs:
fail-fast: false
matrix:
php: [8.4, 8.3, 8.2]
laravel: [11.x]
laravel: [12.x, 11.x]
stability: [prefer-lowest, prefer-stable]

name: Tests - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - PostgreSQL 13
@@ -172,8 +172,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ 8.3, 8.2 ]
laravel: [ 11.x ]
php: [8.4, 8.3, 8.2]
laravel: [12.x, 11.x]
stability: [ prefer-lowest, prefer-stable ]

name: Tests - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - PostgreSQL 14
@@ -229,8 +229,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ 8.3, 8.2 ]
laravel: [ 11.x ]
php: [8.4, 8.3, 8.2]
laravel: [12.x, 11.x]
stability: [ prefer-lowest, prefer-stable ]

name: Tests - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - PostgreSQL 15
@@ -274,8 +274,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ 8.3, 8.2 ]
laravel: [ 11.x ]
php: [8.4, 8.3, 8.2]
laravel: [12.x, 11.x]
stability: [ prefer-lowest, prefer-stable ]

name: Tests - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - SQLite
26 changes: 13 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
@@ -25,16 +25,16 @@
"filament/filament": "^3.2.57",
"filament/spatie-laravel-settings-plugin": "^3.2",
"guzzlehttp/guzzle": "^7.8",
"illuminate/cache": "^11.35.0",
"illuminate/console": "^11.35.0",
"illuminate/database": "^11.35.0",
"illuminate/events": "^11.35.0",
"illuminate/queue": "^11.35.0",
"illuminate/support": "^11.35.0",
"illuminate/cache": "^11.35.0|^12.0",
"illuminate/console": "^11.35.0|^12.0",
"illuminate/database": "^11.35.0|^12.0",
"illuminate/events": "^11.35.0|^12.0",
"illuminate/queue": "^11.35.0|^12.0",
"illuminate/support": "^11.35.0|^12.0",
"laravel/sanctum": "^4.0",
"nesbot/carbon": "^2.70",
"nesbot/carbon": "^2.70|^3.0",
"spatie/laravel-data": "^4.11",
"spatie/laravel-query-builder": "^5.5",
"spatie/laravel-query-builder": "^6.3",
"spatie/laravel-settings": "^3.2",
"spatie/laravel-webhook-server": "^3.8",
"timacdonald/json-api": "^1.0.0-beta.4",
@@ -45,11 +45,11 @@
"larastan/larastan": "^3.4",
"laravel/pail": "^1.1",
"laravel/pint": "^1.21",
"orchestra/testbench": "^9.5.1",
"pestphp/pest": "^3.2",
"pestphp/pest-plugin-laravel": "^3.0",
"pestphp/pest-plugin-livewire": "*",
"pestphp/pest-plugin-type-coverage": "^3.3"
"orchestra/testbench": "^9.5.1|^10.0",
"pestphp/pest": "^3.8",
"pestphp/pest-plugin-laravel": "^3.7",
"pestphp/pest-plugin-livewire": "^v3.0",
"pestphp/pest-plugin-type-coverage": "^3.5"
},
"minimum-stability": "dev",
"prefer-stable": true,
19 changes: 11 additions & 8 deletions src/Http/Controllers/Api/IncidentController.php
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
use Dedoc\Scramble\Attributes\Group;
use Dedoc\Scramble\Attributes\QueryParameter;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Http\Response;
use Illuminate\Pagination\Paginator;
@@ -41,22 +42,24 @@ class IncidentController extends Controller
*/
#[QueryParameter('per_page', 'How many items to show per page.', type: 'int', default: 15, example: 20)]
#[QueryParameter('page', 'Which page to show.', type: 'int', example: 2)]
public function index()
public function index(Request $request)
{
$query = Incident::query()
->when(! request('sort'), function (Builder $builder) {
$builder->orderByDesc('created_at');
});
// $query = Incident::query()
// ->when(!$request->has('sort'), function (Builder $builder) {
// $builder->orderByDesc('created_at');
// });

$incidents = QueryBuilder::for($query)
$incidents = QueryBuilder::for(Incident::query())
->allowedIncludes(self::ALLOWED_INCLUDES)
->allowedFilters([
'name',
AllowedFilter::exact('status'),
'occurred_at',
AllowedFilter::scope('occurs_after'),
AllowedFilter::scope('occurs_before'),
AllowedFilter::scope('occurs_on'),
])
->allowedSorts(['name', 'status', 'id'])
->simplePaginate(request('per_page', 15));
->simplePaginate($request->input('per_page', 15));

return IncidentResource::collection($incidents);
}
15 changes: 15 additions & 0 deletions src/Models/Incident.php
Original file line number Diff line number Diff line change
@@ -171,6 +171,21 @@ public function scopeStickied(Builder $query): void
$query->where('stickied', true);
}

public function scopeOccursAfter(Builder $query, $date): void
{
$query->where('occurred_at', '>=', $date);
}

public function scopeOccursBefore(Builder $query, $date): void
{
$query->where('occurred_at', '<=', $date);
}

public function scopeOccursOn(Builder $query, $date): void
{
$query->whereDate('occurred_at', $date);
}

/**
* @return Attribute<Carbon, never>
*/
20 changes: 14 additions & 6 deletions tests/Feature/Api/IncidentTest.php
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
use function Pest\Laravel\getJson;
use function Pest\Laravel\postJson;
use function Pest\Laravel\putJson;
use function Pest\Laravel\withoutExceptionHandling;

it('can list incidents', function () {
Incident::factory(2)->create();
@@ -144,19 +145,26 @@

it('can filter incidents by occurred at date', function () {
Incident::factory(20)->create([
'occurred_at' => '2019-01-01',
'occurred_at' => '2019-01-01 00:00:00',
]);
$incident = Incident::factory()->create([
'occurred_at' => '2023-01-01',
'occurred_at' => '2025-01-01 00:00:00',
]);

$query = http_build_query([
withoutExceptionHandling();

dd(route('cachet.api.incidents.index', [
'filter' => [
'occurred_at' => '2023-01-01',
'occurs_after' => '2024-12-31',
],
]);
]));

$response = getJson('/status/api/incidents?'.$query);
$response = getJson(route('cachet.api.incidents.index', [
'filter' => [
'occurs_after' => '2024-12-31',
],
]))
->assertOk();

$response->assertJsonCount(1, 'data');
$response->assertJsonPath('data.0.attributes.id', $incident->id);