Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
stability: [prefer-stable]
php: [8.2, 8.3, 8.4]
laravel: [11]
laravel: [12]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

Expand Down
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
],
"require": {
"php": "^8.2",
"api-ecosystem-for-laravel/dingo-api": "^4.4.1",
"php-open-source-saver/jwt-auth": "^2.7",
"illuminate/support": "^11.0",
"api-ecosystem-for-laravel/dingo-api": "^4.6",
"php-open-source-saver/jwt-auth": "^2.8",
"illuminate/support": "^12.0",
"ramsey/uuid": "^4.7",
"nesbot/carbon": "^2.0|^3.0"
"nesbot/carbon": "^3.0"
},
"require-dev": {
"ext-json": "*",
"beyondcode/laravel-dump-server": "^2.0",
"fakerphp/faker": "^1.23",
"beyondcode/laravel-dump-server": "^2.1",
"fakerphp/faker": "^1.24",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.6",
"phpunit/phpunit": "^11.5",
"orchestra/testbench": "^9.9"
"orchestra/testbench": "^10.3"
},
"autoload": {
"psr-4": {
Expand All @@ -37,9 +37,10 @@
"Specialtactics\\L5Api\\Tests\\": "test/tests/",
"Specialtactics\\L5Api\\Test\\Mocks\\": "test/mocks/",
"App\\": "test/app/",
"Database\\": "test/database/"
"Database\\Factories\\": "test/database/factories/",
"Database\\Seeders\\": "test/database/seeders/"
},
"classmap": ["test/database/seeds/"]
"classmap": ["test/database/migrations/"]
},
"extra": {
"laravel": {
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Please go to [The boilerplate wiki](https://github.com/specialtactics/laravel-ap

| Laravel Version | Boilerplate Version | Minimum PHP Version | Support Status |
|-----------------|---------------------|---------------------|----------------|
| 12.x | 7.x.x | 8.2 | Supported |
| 11.x | 6.x.x | 8.2 | Supported |
| 10.x | 5.x.x | 8.1 | Supported |
| 10.x | 5.x.x | 8.1 | Not Supported |
| 9.x | 4.x.x | 8.0 | Not Supported |
| 8.x | 3.x.x | 7.3 | Not Supported |
| 7.x | 2.x.x | 7.2.5 | Not Supported |
Expand Down
25 changes: 15 additions & 10 deletions test/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Support\Str;
use PHPOpenSourceSaver\JWTAuth\Contracts\JWTSubject;
use \Illuminate\Support\Facades\Hash;
use App\Models\Role;
use Database\Factories\UserFactory;

Expand Down Expand Up @@ -43,29 +42,35 @@ class User extends BaseModel implements
'name', 'email', 'password', 'primary_role'
];

protected $casts = [
'verifiable_until' => 'datetime',
'password' => 'hashed',
];

/**
* The attributes that should be hidden for arrays and API output
*/
protected $hidden = [
'password', 'remember_token', 'primary_role',
];

/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}

/**
* Model's boot function
*/
public static function boot(): void
{
parent::boot();

static::creating(function (User $user) {
if (is_null($user->password)) {
$user->password = Hash::make(Str::random(64));
}
static::saving(function (User $user) {
$user->email = Str::lower($user->email);
});
}

Expand Down
78 changes: 78 additions & 0 deletions test/database/factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\Role;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

/**
* @extends Factory<User>
*/
class UserFactory extends Factory
{
public const DEFAULT_PASSWORD = 'secret';

/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;

protected static ?Collection $allRoles = null;

/**
* Retrieve all roles
*/
public static function getAllRoles(): Collection
{
if (is_null(static::$allRoles)) {
static::$allRoles = Role::all();
}

return static::$allRoles;
}

/**
* Define the model's default state.
*/
public function definition(): array
{
return [
'name' => $this->faker->name(),
'email' => microtime(true) . '_' . $this->faker->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::DEFAULT_PASSWORD,
'remember_token' => Str::random(10),
'active' => true,
];
}

public function adminRole(): UserFactory
{
return $this->state(function (array $attributes): array {
return [
'primary_role' => static::getAllRoles()
->firstWhere('name', '=', Role::ROLE_ADMIN)
->getKey(),
];
});
}

/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): UserFactory
{
return $this->state(function (array $attributes): array {
return [
'email_verified_at' => null,
];
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public function up()
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->boolean('active')->default(true);

$table->uuid('primary_role')->nullable();
$table->foreign('primary_role')->references('role_id')->on('roles')->onDelete('set null');
$table->timestamp('email_verified_at')->nullable();

$table->primary('user_id');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class BaseSeeder extends Seeder {
Expand All @@ -9,23 +11,23 @@ class BaseSeeder extends Seeder {
public $faker = null;

/**
* Run the database seeds.
* Run the database Seeders.
*
* @return void
*/
public function run()
{
// You can set the locale of your seeder as a parameter to the create function
// Available locales: https://github.com/fzaninotto/Faker/tree/master/src/Faker/Provider
$this->faker = Faker\Factory::create();
$this->faker = \Faker\Factory::create();

$this->before();

// Run in any environment
$this->runAlways();

// Production Only
if (App::environment() == 'production') {
if (app()->environment() === 'production') {
$this->runProduction();
}
// Fake environments
Expand All @@ -37,23 +39,23 @@ public function run()
}

/**
* Run fake seeds - for non production environments
* Run fake Seeders - for non production environments
*
* @return void
*/
public function runFake() {
}

/**
* Run seeds to be ran only on production environments
* Run Seeders to be ran only on production environments
*
* @return void
*/
public function runProduction() {
}

/**
* Run seeds to be ran on every environment (including production)
* Run Seeders to be ran on every environment (including production)
*
* @return void
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
* Run the database Seeders.
*
* @return void
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

namespace Database\Seeders;

use App\Models\Forum;

class ForumsSeeder extends BaseSeeder
{
/**
* Run fake seeds - for non production environments
* Run fake Seeders - for non production environments
*
* @return mixed
*/
Expand All @@ -16,7 +18,7 @@ public function runFake() {
}

/**
* Run seeds to be ran only on production environments
* Run Seeders to be ran only on production environments
*
* @return mixed
*/
Expand All @@ -25,7 +27,7 @@ public function runProduction() {
}

/**
* Run seeds to be ran on every environment (including production)
* Run Seeders to be ran on every environment (including production)
*
* @return mixed
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

namespace Database\Seeders;

use App\Models\Forum;
use App\Models\Topic;
use App\Models\Post;

class PostsSeeder extends BaseSeeder
{
/**
* Run fake seeds - for non production environments
* Run fake Seeders - for non production environments
*
* @return mixed
*/
Expand All @@ -26,7 +28,7 @@ public function runFake() {
}

/**
* Run seeds to be ran only on production environments
* Run Seeders to be ran only on production environments
*
* @return mixed
*/
Expand All @@ -35,7 +37,7 @@ public function runProduction() {
}

/**
* Run seeds to be ran on every environment (including production)
* Run Seeders to be ran on every environment (including production)
*
* @return mixed
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Database\Seeders;

use App\Models\Role;

class RoleTableSeeder extends BaseSeeder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

namespace Database\Seeders;

class TagsSeeder extends BaseSeeder
{
/**
* Run fake seeds - for non production environments
* Run fake Seeders - for non production environments
*
* @return mixed
*/
Expand All @@ -12,7 +14,7 @@ public function runFake() {
}

/**
* Run seeds to be ran only on production environments
* Run Seeders to be ran only on production environments
*
* @return mixed
*/
Expand All @@ -21,7 +23,7 @@ public function runProduction() {
}

/**
* Run seeds to be ran on every environment (including production)
* Run Seeders to be ran on every environment (including production)
*
* @return mixed
*/
Expand Down
Loading