Skip to content

Commit 644742f

Browse files
committed
feat(versioning): add api versioning
1 parent b91ceba commit 644742f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+159
-50
lines changed

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
# Laravel 10 API skeleton template
22

3-
Basic Laravel 10 API skeleton template with few packages installed to use as a starting point.
3+
Basic **Laravel 10** basic API skeleton template with few packages installed to use as a starting point.
4+
5+
## Features
6+
7+
- Prepared for API versioning.
8+
- `Src` namespace declared for a DDD approach.
9+
10+
## Included packages
11+
12+
Take a look at the `composer.json` file to see the full list of packages included.

app/Console/Kernel.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Console;
46

57
use Illuminate\Console\Scheduling\Schedule;

app/Exceptions/Handler.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Exceptions;
46

57
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
@@ -23,8 +25,8 @@ class Handler extends ExceptionHandler
2325
*/
2426
public function register(): void
2527
{
26-
$this->reportable(function (Throwable $e) {
27-
//
28+
$this->reportable(function (Throwable $e): void {
29+
2830
});
2931
}
3032
}

app/Http/Controllers/Controller.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Controllers;
46

57
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
@@ -8,5 +10,6 @@
810

911
class Controller extends BaseController
1012
{
11-
use AuthorizesRequests, ValidatesRequests;
13+
use AuthorizesRequests;
14+
use ValidatesRequests;
1215
}

app/Http/Kernel.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http;
46

57
use Illuminate\Foundation\Http\Kernel as HttpKernel;
@@ -15,11 +17,11 @@ class Kernel extends HttpKernel
1517
*/
1618
protected $middleware = [
1719
// \App\Http\Middleware\TrustHosts::class,
18-
\App\Http\Middleware\TrustProxies::class,
20+
Middleware\TrustProxies::class,
1921
\Illuminate\Http\Middleware\HandleCors::class,
20-
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
22+
Middleware\PreventRequestsDuringMaintenance::class,
2123
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
22-
\App\Http\Middleware\TrimStrings::class,
24+
Middleware\TrimStrings::class,
2325
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
2426
];
2527

@@ -30,11 +32,11 @@ class Kernel extends HttpKernel
3032
*/
3133
protected $middlewareGroups = [
3234
'web' => [
33-
\App\Http\Middleware\EncryptCookies::class,
35+
Middleware\EncryptCookies::class,
3436
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
3537
\Illuminate\Session\Middleware\StartSession::class,
3638
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
37-
\App\Http\Middleware\VerifyCsrfToken::class,
39+
Middleware\VerifyCsrfToken::class,
3840
\Illuminate\Routing\Middleware\SubstituteBindings::class,
3941
],
4042

@@ -53,15 +55,15 @@ class Kernel extends HttpKernel
5355
* @var array<string, class-string|string>
5456
*/
5557
protected $middlewareAliases = [
56-
'auth' => \App\Http\Middleware\Authenticate::class,
58+
'auth' => Middleware\Authenticate::class,
5759
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
5860
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
5961
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
6062
'can' => \Illuminate\Auth\Middleware\Authorize::class,
61-
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
63+
'guest' => Middleware\RedirectIfAuthenticated::class,
6264
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
6365
'precognitive' => \Illuminate\Foundation\Http\Middleware\HandlePrecognitiveRequests::class,
64-
'signed' => \App\Http\Middleware\ValidateSignature::class,
66+
'signed' => Middleware\ValidateSignature::class,
6567
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
6668
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
6769
];

app/Http/Middleware/Authenticate.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Middleware;
46

57
use Illuminate\Auth\Middleware\Authenticate as Middleware;

app/Http/Middleware/EncryptCookies.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Middleware;
46

57
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
@@ -12,6 +14,6 @@ class EncryptCookies extends Middleware
1214
* @var array<int, string>
1315
*/
1416
protected $except = [
15-
//
17+
1618
];
1719
}

app/Http/Middleware/PreventRequestsDuringMaintenance.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Middleware;
46

57
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
@@ -12,6 +14,6 @@ class PreventRequestsDuringMaintenance extends Middleware
1214
* @var array<int, string>
1315
*/
1416
protected $except = [
15-
//
17+
1618
];
1719
}

app/Http/Middleware/RedirectIfAuthenticated.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Middleware;
46

57
use App\Providers\RouteServiceProvider;
@@ -13,7 +15,7 @@ class RedirectIfAuthenticated
1315
/**
1416
* Handle an incoming request.
1517
*
16-
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
18+
* @param Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
1719
*/
1820
public function handle(Request $request, Closure $next, string ...$guards): Response
1921
{

app/Http/Middleware/TrimStrings.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Middleware;
46

57
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;

app/Http/Middleware/TrustHosts.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Middleware;
46

57
use Illuminate\Http\Middleware\TrustHosts as Middleware;

app/Http/Middleware/TrustProxies.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Middleware;
46

57
use Illuminate\Http\Middleware\TrustProxies as Middleware;

app/Http/Middleware/ValidateSignature.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Middleware;
46

57
use Illuminate\Routing\Middleware\ValidateSignature as Middleware;

app/Http/Middleware/VerifyCsrfToken.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Middleware;
46

57
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
@@ -12,6 +14,6 @@ class VerifyCsrfToken extends Middleware
1214
* @var array<int, string>
1315
*/
1416
protected $except = [
15-
//
17+
1618
];
1719
}

app/Models/User.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Models;
46

57
// use Illuminate\Contracts\Auth\MustVerifyEmail;
@@ -10,7 +12,9 @@
1012

1113
class User extends Authenticatable
1214
{
13-
use HasApiTokens, HasFactory, Notifiable;
15+
use HasApiTokens;
16+
use HasFactory;
17+
use Notifiable;
1418

1519
/**
1620
* The attributes that are mass assignable.

app/Providers/AppServiceProvider.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Providers;
46

57
use Illuminate\Support\Facades\Schema;
@@ -12,7 +14,7 @@ class AppServiceProvider extends ServiceProvider
1214
*/
1315
public function register(): void
1416
{
15-
//
17+
1618
}
1719

1820
/**

app/Providers/AuthServiceProvider.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Providers;
46

57
// use Illuminate\Support\Facades\Gate;
@@ -13,14 +15,14 @@ class AuthServiceProvider extends ServiceProvider
1315
* @var array<class-string, class-string>
1416
*/
1517
protected $policies = [
16-
//
18+
1719
];
1820

1921
/**
2022
* Register any authentication / authorization services.
2123
*/
2224
public function boot(): void
2325
{
24-
//
26+
2527
}
2628
}

app/Providers/BroadcastServiceProvider.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Providers;
46

57
use Illuminate\Support\Facades\Broadcast;

app/Providers/EventServiceProvider.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Providers;
46

57
use Illuminate\Auth\Events\Registered;
@@ -25,7 +27,7 @@ class EventServiceProvider extends ServiceProvider
2527
*/
2628
public function boot(): void
2729
{
28-
//
30+
2931
}
3032

3133
/**

app/Providers/RouteServiceProvider.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Providers;
46

57
use Illuminate\Cache\RateLimiting\Limit;
@@ -24,14 +26,12 @@ class RouteServiceProvider extends ServiceProvider
2426
*/
2527
public function boot(): void
2628
{
27-
RateLimiter::for('api', function (Request $request) {
28-
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
29-
});
29+
RateLimiter::for('api', fn (Request $request) => Limit::perMinute(60)->by($request->user()?->id ?: $request->ip()));
3030

31-
$this->routes(function () {
31+
$this->routes(function (): void {
3232
Route::middleware('api')
3333
->prefix('api')
34-
->group(base_path('routes/api.php'));
34+
->group(base_path('routes/Api/api.php'));
3535

3636
Route::middleware('web')
3737
->group(base_path('routes/web.php'));

bootstrap/app.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
|--------------------------------------------------------------------------
57
| Create The Application

config/app.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use Illuminate\Support\Facades\Facade;
46
use Illuminate\Support\ServiceProvider;
57

config/auth.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
return [
46

57
/*

config/broadcasting.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
return [
46

57
/*
@@ -41,7 +43,7 @@
4143
'port' => env('PUSHER_PORT', 443),
4244
'scheme' => env('PUSHER_SCHEME', 'https'),
4345
'encrypted' => true,
44-
'useTLS' => env('PUSHER_SCHEME', 'https') === 'https',
46+
'useTLS' => 'https' === env('PUSHER_SCHEME', 'https'),
4547
],
4648
'client_options' => [
4749
// Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html

config/cache.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use Illuminate\Support\Str;
46

57
return [

config/cors.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
return [
46

57
/*

config/database.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use Illuminate\Support\Str;
46

57
return [

0 commit comments

Comments
 (0)