Skip to content

Commit df422d4

Browse files
committed
wip
1 parent 26f40ca commit df422d4

File tree

12 files changed

+113
-96
lines changed

12 files changed

+113
-96
lines changed

src/Http/Controllers/Auth/LoginController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function login(Request $request): RedirectResponse
5959

6060
if ($request->user()->can('viewRoot') && $request->user()->shouldTwoFactorAuthenticate($request)) {
6161
$request->user()->notify(
62-
new AuthCodeNotification($request->user()->generateAuthCode())
62+
new AuthCodeNotification($request->user()->authCodes()->create())
6363
);
6464

6565
$request->session()->flash('status', __('The two factor authentication link has been sent!'));

src/Http/Controllers/Auth/TwoFactorController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function verify(Request $request): RedirectResponse
7979
*/
8080
public function resend(Request $request): RedirectResponse
8181
{
82-
$code = $request->user()->generateAuthCode();
82+
$code = $request->user()->authCodes()->create();
8383

8484
$request->user()->notify(new AuthCodeNotification($code));
8585

src/Jobs/MoveFile.php

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,6 @@ class MoveFile implements ShouldQueue
2222
use Queueable;
2323
use SerializesModels;
2424

25-
/**
26-
* The medium instance.
27-
*/
28-
public Medium $medium;
29-
30-
/**
31-
* The path to the file.
32-
*/
33-
public string $path;
34-
35-
/**
36-
* Indicates if the original file should be preserved.
37-
*/
38-
public bool $preserve = true;
39-
4025
/**
4126
* Delete the job if its models no longer exist.
4227
*
@@ -47,11 +32,12 @@ class MoveFile implements ShouldQueue
4732
/**
4833
* Create a new job instance.
4934
*/
50-
public function __construct(Medium $medium, string $path, bool $preserve = true)
51-
{
52-
$this->path = $path;
53-
$this->medium = $medium;
54-
$this->preserve = $preserve;
35+
public function __construct(
36+
public readonly Medium $medium,
37+
public readonly string $path,
38+
public readonly bool $preserve = true
39+
) {
40+
//
5541
}
5642

5743
/**

src/Jobs/PerformConversions.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ class PerformConversions implements ShouldQueue
1919
use Queueable;
2020
use SerializesModels;
2121

22-
/**
23-
* The medium instance.
24-
*/
25-
public Medium $medium;
26-
2722
/**
2823
* Delete the job if its models no longer exist.
2924
*
@@ -34,9 +29,9 @@ class PerformConversions implements ShouldQueue
3429
/**
3530
* Create a new job instance.
3631
*/
37-
public function __construct(Medium $medium)
32+
public function __construct(public readonly Medium $medium)
3833
{
39-
$this->medium = $medium;
34+
//
4035
}
4136

4237
/**

src/Models/Attachment.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,16 @@ class Attachment extends MorphPivot
3333
* @var string
3434
*/
3535
protected $table = 'root_mediables';
36+
37+
/**
38+
* Get the attributes that should be cast.
39+
*
40+
* @return array{'meta':'json'}
41+
*/
42+
protected function casts(): array
43+
{
44+
return [
45+
'meta' => 'json',
46+
];
47+
}
3648
}

src/Models/AuthCode.php

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@ class AuthCode extends Model implements Contract
1818
use HasFactory;
1919
use InteractsWithProxy;
2020

21-
/**
22-
* The attributes that should be cast to native types.
23-
*
24-
* @var array<string, string>
25-
*/
26-
protected $casts = [
27-
'code' => 'int',
28-
'expires_at' => 'datetime',
29-
];
30-
3121
/**
3222
* The attributes that are mass assignable.
3323
*
@@ -42,6 +32,30 @@ class AuthCode extends Model implements Contract
4232
*/
4333
protected $table = 'root_auth_codes';
4434

35+
/**
36+
* Create a new Eloquent model instance.
37+
*
38+
* @param array<string, mixed> $attributes
39+
*/
40+
public function __construct(array $attributes = [])
41+
{
42+
parent::__construct(
43+
array_merge(['code' => static::generate()], $attributes)
44+
);
45+
}
46+
47+
/**
48+
* Generate a new code.
49+
*/
50+
public static function generate(): string
51+
{
52+
do {
53+
$code = str_pad((string) random_int(0, 999999), 6, '0', STR_PAD_LEFT);
54+
} while (preg_match('/(\d)\1{2,}/', $code) === 1);
55+
56+
return $code;
57+
}
58+
4559
/**
4660
* Get the proxied interface.
4761
*/
@@ -58,6 +72,19 @@ protected static function newFactory(): AuthCodeFactory
5872
return AuthCodeFactory::new();
5973
}
6074

75+
/**
76+
* Get the attributes that should be cast.
77+
*
78+
* @return array{'code':'int', 'expires_at':'datetime'}
79+
*/
80+
protected function casts(): array
81+
{
82+
return [
83+
'code' => 'int',
84+
'expires_at' => 'datetime',
85+
];
86+
}
87+
6188
/**
6289
* Get the user for the model.
6390
*/

src/Models/Event.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ class Event extends Model implements Contract
1717
use HasFactory;
1818
use InteractsWithProxy;
1919

20-
/**
21-
* The attributes that should be cast to native types.
22-
*
23-
* @var array<string, string>
24-
*/
25-
protected $casts = [
26-
'payload' => 'json',
27-
];
28-
2920
/**
3021
* The attributes that are mass assignable.
3122
*
@@ -59,6 +50,18 @@ protected static function newFactory(): EventFactory
5950
return EventFactory::new();
6051
}
6152

53+
/**
54+
* Get the attributes that should be cast.
55+
*
56+
* @return array{'payload':'json'}
57+
*/
58+
protected function casts(): array
59+
{
60+
return [
61+
'payload' => 'json',
62+
];
63+
}
64+
6265
/**
6366
* Get the event target.
6467
*/

src/Models/Medium.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Cone\Root\Support\Facades\Conversion;
1414
use Cone\Root\Traits\Filterable;
1515
use Cone\Root\Traits\InteractsWithProxy;
16+
use Illuminate\Database\Eloquent\Attributes\Scope;
1617
use Illuminate\Database\Eloquent\Builder;
1718
use Illuminate\Database\Eloquent\Casts\Attribute;
1819
use Illuminate\Database\Eloquent\Concerns\HasUuids;
@@ -55,15 +56,6 @@ class Medium extends Model implements Contract
5556
'properties' => '{"conversions":[]}',
5657
];
5758

58-
/**
59-
* The attributes that should be cast to native types.
60-
*
61-
* @var array<string, string>
62-
*/
63-
protected $casts = [
64-
'properties' => 'json',
65-
];
66-
6759
/**
6860
* The attributes that are mass assignable.
6961
*
@@ -166,6 +158,18 @@ public static function fromPath(string $path, array $attributes = []): static
166158
], $attributes));
167159
}
168160

161+
/**
162+
* Get the attributes that should be cast.
163+
*
164+
* @return array{'properties':'json'}
165+
*/
166+
protected function casts(): array
167+
{
168+
return [
169+
'properties' => 'json',
170+
];
171+
}
172+
169173
/**
170174
* {@inheritdoc}
171175
*/
@@ -313,7 +317,8 @@ public function download(?string $conversion = null): BinaryFileResponse
313317
/**
314318
* Scope the query only to the given search term.
315319
*/
316-
public function scopeSearch(Builder $query, ?string $value = null): Builder
320+
#[Scope]
321+
protected function search(Builder $query, string $value): Builder
317322
{
318323
if (is_null($value)) {
319324
return $query;
@@ -325,7 +330,8 @@ public function scopeSearch(Builder $query, ?string $value = null): Builder
325330
/**
326331
* Scope the query only to the given type.
327332
*/
328-
public function scopeType(Builder $query, string $value): Builder
333+
#[Scope]
334+
protected function type(Builder $query, string $value): Builder
329335
{
330336
return match ($value) {
331337
'image' => $query->where($query->qualifyColumn('mime_type'), 'like', 'image%'),

src/Models/Meta.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ class Meta extends Model implements Contract
1717
use HasFactory;
1818
use InteractsWithProxy;
1919

20-
/**
21-
* The attributes that should be cast to native types.
22-
*
23-
* @var array<string, string>
24-
*/
25-
protected $casts = [
26-
'value' => MetaValue::class,
27-
];
28-
2920
/**
3021
* The attributes that are mass assignable.
3122
*
@@ -59,6 +50,18 @@ protected static function newFactory(): MetaFactory
5950
return MetaFactory::new();
6051
}
6152

53+
/**
54+
* Get the attributes that should be cast.
55+
*
56+
* @return array{'value':'\Cone\Root\Casts\MetaValue'}
57+
*/
58+
protected function casts(): array
59+
{
60+
return [
61+
'value' => MetaValue::class,
62+
];
63+
}
64+
6265
/**
6366
* {@inheritdoc}
6467
*/

src/Models/Translation.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ class Translation extends Model implements Contract
1717
use HasFactory;
1818
use InteractsWithProxy;
1919

20-
/**
21-
* The attributes that should be cast to native types.
22-
*
23-
* @var array<string, string>
24-
*/
25-
protected $casts = [
26-
'values' => AsArrayObject::class,
27-
];
28-
2920
/**
3021
* The attributes that are mass assignable.
3122
*
@@ -80,6 +71,18 @@ public static function getTranslatableLocale(): string
8071
return static::$translatableLocale;
8172
}
8273

74+
/**
75+
* Get the attributes that should be cast.
76+
*
77+
* @return array{'values':'\Illuminate\Database\Eloquent\Casts\AsArrayObject'}
78+
*/
79+
protected function casts(): array
80+
{
81+
return [
82+
'values' => AsArrayObject::class,
83+
];
84+
}
85+
8386
/**
8487
* Get the translatable model for the translation.
8588
*/

0 commit comments

Comments
 (0)