1 | <?php |
||
2 | |||
3 | namespace App; |
||
4 | |||
5 | use Illuminate\Support\Facades\Auth; |
||
6 | |||
7 | class Competitor extends \Xoco70\LaravelTournaments\Models\Competitor |
||
8 | { |
||
9 | 3 | public static function getShortId($categories, Tournament $tournament) |
|
10 | { |
||
11 | 3 | $competitor = static::where('user_id', Auth::user()->id) |
|
12 | 3 | ->whereIn('championship_id', $categories)->first(); |
|
13 | |||
14 | 3 | if ($competitor != null) { |
|
15 | 1 | return $competitor->short_id; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
16 | } |
||
17 | 3 | return $tournament->competitors()->max('short_id') + 1; |
|
18 | } |
||
19 | |||
20 | /** |
||
21 | * @param $attributes |
||
22 | * @return mixed $user |
||
23 | */ |
||
24 | 2 | public static function createUser($attributes) |
|
25 | { |
||
26 | 2 | $user = User::where(['email' => $attributes['email']])->withTrashed()->first(); |
|
27 | |||
28 | 2 | if ($user == null) { |
|
29 | $password = str_random(8); |
||
30 | $user = User::create([ |
||
31 | 'firstname' => $attributes['firstname'], |
||
32 | 'lastname' => $attributes['lastname'], |
||
33 | 'name' => $attributes['name'], |
||
34 | 'email' => $attributes['email'] |
||
35 | ]); |
||
36 | $user->clearPassword = $password; |
||
37 | } |
||
38 | // If user is deleted, this is restoring the user only, but not his asset ( tournaments, categories, etc.) |
||
39 | 2 | if ($user->isDeleted()) { |
|
40 | 1 | $user->deleted_at = null; |
|
41 | 1 | $user->save(); |
|
42 | } |
||
43 | 2 | return $user; |
|
44 | } |
||
45 | } |
||
46 |