Skip to content

Commit 68fb082

Browse files
committed
WIP
1 parent 7346975 commit 68fb082

File tree

18 files changed

+139
-226
lines changed

18 files changed

+139
-226
lines changed

app/Console/Commands/CompareDocument.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function updateVersion(string $version): void
4545
$docs->update();
4646
} catch (\Exception $exception) {
4747
// Log a warning if an error occurs during update
48-
$this->warn("Failed to update document: {$exception->getMessage()}");
48+
$this->warn("Failed to update document: {$exception->getMessage()} {$exception->getFile()} {$exception->getLine()}");
4949
}
5050
});
5151
}

app/Http/Controllers/MeetController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function index()
2626
$past = Meet::approved()
2727
->whereDate('start_date', '<', now())
2828
->orderBy('start_date', 'desc')
29-
->simplePaginate(5);
29+
->simplePaginate(6);
3030

3131
return view('meet.index', [
3232
'most' => $most,

app/Models/CodeSnippet.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Models;
44

5+
use App\Models\Concerns\HasAuthor;
56
use Illuminate\Database\Eloquent\Concerns\HasUuids;
67
use Illuminate\Database\Eloquent\Factories\HasFactory;
78
use Illuminate\Database\Eloquent\Model;
@@ -11,7 +12,7 @@
1112

1213
class CodeSnippet extends Model
1314
{
14-
use AsSource, Chartable, HasFactory, HasUuids, Prunable;
15+
use AsSource, Chartable, HasFactory, HasUuids, Prunable, HasAuthor;
1516

1617
/**
1718
* The attributes that are mass assignable.

app/Models/Comment.php

+3-33
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace App\Models;
44

5+
use App\Models\Concerns\Approvable;
6+
use App\Models\Concerns\HasAuthor;
57
use Illuminate\Database\Eloquent\Builder;
68
use Illuminate\Database\Eloquent\Factories\HasFactory;
79
use Illuminate\Database\Eloquent\Model;
@@ -14,7 +16,7 @@
1416

1517
class Comment extends Model
1618
{
17-
use Chartable, HasFactory, Likeable, SoftDeletes;
19+
use Chartable, HasFactory, Likeable, SoftDeletes, Approvable, HasAuthor;
1820

1921
/**
2022
* The attributes that are mass assignable.
@@ -67,16 +69,6 @@ public function parent()
6769
return $this->belongsTo(static::class, 'parent_id');
6870
}
6971

70-
/**
71-
* Verify if the current comment is approved.
72-
*
73-
* @return bool
74-
*/
75-
public function isApproved(): bool
76-
{
77-
return $this->attributes['approved'] === 1 || $this->attributes['approved'] === true;
78-
}
79-
8072
/**
8173
* Verify if the current comment is a reply from another comment.
8274
*
@@ -97,28 +89,6 @@ public function hasReplies(): bool
9789
return count($this->replies) > 0;
9890
}
9991

100-
/**
101-
* Get the author of the comment.
102-
*
103-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
104-
*/
105-
public function author(): BelongsTo
106-
{
107-
return $this->belongsTo(User::class, 'user_id');
108-
}
109-
110-
/**
111-
* Where clause for only approved comments.
112-
*
113-
* @param Builder $query
114-
*
115-
* @return Builder
116-
*/
117-
public function scopeApproved(Builder $query): Builder
118-
{
119-
return $query->where('approved', 1);
120-
}
121-
12292
/**
12393
* Convert URLs in text to HTML links.
12494
*

app/Models/Concerns/Approvable.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Models\Concerns;
4+
5+
use Illuminate\Database\Eloquent\Builder;
6+
7+
trait Approvable
8+
{
9+
/**
10+
* Scope a query to only include approved items.
11+
*
12+
* @param Builder $query
13+
* @param bool $approved
14+
*
15+
* @return Builder
16+
*/
17+
public function scopeApproved(Builder $query, bool $approved = true): Builder
18+
{
19+
return $query->where('approved', $approved);
20+
}
21+
22+
/**
23+
* Verify if the current item is approved.
24+
*
25+
* @return bool
26+
*/
27+
public function isApproved(): bool
28+
{
29+
return $this->attributes['approved'] === 1 || $this->attributes['approved'] === true;
30+
}
31+
}

app/Models/Concerns/HasAuthor.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Models\Concerns;
4+
5+
use App\Models\User;
6+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7+
8+
trait HasAuthor
9+
{
10+
/**
11+
* Get the user that owns the item.
12+
*
13+
* @return BelongsTo
14+
*/
15+
public function user(): BelongsTo
16+
{
17+
return $this->belongsTo(User::class);
18+
}
19+
20+
/**
21+
* Get the author of the item.
22+
*
23+
* @return BelongsTo
24+
*/
25+
public function author(): BelongsTo
26+
{
27+
return $this->user();
28+
}
29+
}

app/Models/IdeaKey.php

+2-11
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,15 @@
22

33
namespace App\Models;
44

5+
use App\Models\Concerns\HasAuthor;
56
use Illuminate\Database\Eloquent\Concerns\HasUuids;
67
use Illuminate\Database\Eloquent\Factories\HasFactory;
78
use Illuminate\Database\Eloquent\Model;
89
use Orchid\Metrics\Chartable;
910

1011
class IdeaKey extends Model
1112
{
12-
use Chartable, HasFactory, HasUuids;
13-
14-
/**
15-
* Get the user associated with the idea key.
16-
*
17-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
18-
*/
19-
public function user(): BelongsTo
20-
{
21-
return $this->belongsTo(User::class);
22-
}
13+
use Chartable, HasFactory, HasUuids, HasAuthor;
2314

2415
/**
2516
* Get the idea request associated with the idea key.

app/Models/IdeaRequest.php

+2-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Models;
44

5+
use App\Models\Concerns\HasAuthor;
56
use Illuminate\Database\Eloquent\Factories\HasFactory;
67
use Illuminate\Database\Eloquent\Model;
78
use Orchid\Filters\Filterable;
@@ -10,7 +11,7 @@
1011

1112
class IdeaRequest extends Model
1213
{
13-
use AsSource, Chartable, Filterable, HasFactory;
14+
use AsSource, Chartable, Filterable, HasFactory, HasAuthor;
1415

1516
/**
1617
* The attributes that are mass assignable.
@@ -26,16 +27,6 @@ class IdeaRequest extends Model
2627
'message',
2728
];
2829

29-
/**
30-
* Get the user associated with the idea request.
31-
*
32-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
33-
*/
34-
public function user()
35-
{
36-
return $this->belongsTo(User::class);
37-
}
38-
3930
/**
4031
* Get the idea key associated with the idea request.
4132
*

app/Models/Meet.php

+3-24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace App\Models;
44

5+
use App\Models\Concerns\Approvable;
6+
use App\Models\Concerns\HasAuthor;
57
use App\Models\Concerns\LogsActivityFillable;
68
use Illuminate\Database\Eloquent\Builder;
79
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -14,7 +16,7 @@
1416

1517
class Meet extends Model
1618
{
17-
use AsSource, Chartable, Filterable, HasFactory, LogsActivityFillable;
19+
use AsSource, Chartable, Filterable, HasFactory, LogsActivityFillable, Approvable, HasAuthor;
1820

1921
/**
2022
* The attributes that are mass assignable.
@@ -73,27 +75,4 @@ class Meet extends Model
7375
'online',
7476
'approved',
7577
];
76-
77-
/**
78-
* Get the author of the meet.
79-
*
80-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
81-
*/
82-
public function author(): BelongsTo
83-
{
84-
return $this->belongsTo(User::class, 'user_id');
85-
}
86-
87-
/**
88-
* Scope a query to only include approved meets.
89-
*
90-
* @param Builder $query
91-
* @param bool $approved
92-
*
93-
* @return Builder
94-
*/
95-
public function scopeApproved(Builder $query, bool $approved = true): Builder
96-
{
97-
return $query->where('approved', $approved);
98-
}
9978
}

app/Models/Package.php

+3-24
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace App\Models;
44

55
use App\Casts\PackageTypeEnum;
6+
use App\Models\Concerns\Approvable;
7+
use App\Models\Concerns\HasAuthor;
68
use App\Models\Concerns\LogsActivityFillable;
79
use App\Presenters\PackagePresenter;
810
use Illuminate\Database\Eloquent\Builder;
@@ -16,7 +18,7 @@
1618

1719
class Package extends Model
1820
{
19-
use AsSource, Chartable, Filterable, HasFactory, LogsActivityFillable;
21+
use AsSource, Chartable, Filterable, HasFactory, LogsActivityFillable, Approvable, HasAuthor;
2022

2123
/**
2224
* The attributes that are mass assignable.
@@ -80,29 +82,6 @@ class Package extends Model
8082
'approved',
8183
];
8284

83-
/**
84-
* Get the author of the package.
85-
*
86-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
87-
*/
88-
public function author(): BelongsTo
89-
{
90-
return $this->belongsTo(User::class, 'user_id');
91-
}
92-
93-
/**
94-
* Scope a query to only include approved packages.
95-
*
96-
* @param Builder $query
97-
* @param bool $approved
98-
*
99-
* @return Builder
100-
*/
101-
public function scopeApproved(Builder $query, bool $approved = true): Builder
102-
{
103-
return $query->where('approved', $approved);
104-
}
105-
10685
/**
10786
* @return \App\Presenters\PackagePresenter
10887
*/

app/Models/Position.php

+3-34
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace App\Models;
44

55
use App\Casts\ScheduleEnum;
6+
use App\Models\Concerns\Approvable;
7+
use App\Models\Concerns\HasAuthor;
68
use App\Models\Concerns\LogsActivityFillable;
79
use App\Presenters\PositionPresenter;
810
use Illuminate\Database\Eloquent\Builder;
@@ -17,7 +19,7 @@
1719

1820
class Position extends Model
1921
{
20-
use AsSource, Chartable, Filterable, HasFactory, LogsActivityFillable;
22+
use AsSource, Chartable, Filterable, HasFactory, LogsActivityFillable, Approvable, HasAuthor;
2123

2224
/**
2325
* The attributes that are mass assignable.
@@ -107,39 +109,6 @@ public static function boot(): void
107109
});
108110
}
109111

110-
/**
111-
* Get the user that owns the position.
112-
*
113-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
114-
*/
115-
public function user(): BelongsTo
116-
{
117-
return $this->belongsTo(User::class);
118-
}
119-
120-
/**
121-
* Get the author of the position.
122-
*
123-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
124-
*/
125-
public function author(): BelongsTo
126-
{
127-
return $this->user();
128-
}
129-
130-
/**
131-
* Scope a query to only include approved positions.
132-
*
133-
* @param Builder $query
134-
* @param bool $approved
135-
*
136-
* @return Builder
137-
*/
138-
public function scopeApproved(Builder $query, bool $approved = true): Builder
139-
{
140-
return $query->where('approved', $approved);
141-
}
142-
143112
/**
144113
* Get the presenter for the model.
145114
*

0 commit comments

Comments
 (0)