1 | <?php |
||
2 | |||
3 | namespace Luilliarcec\UserCommands\Commands; |
||
4 | |||
5 | |||
6 | class RestoreUserCommand extends UserCommand |
||
7 | { |
||
8 | /** |
||
9 | * The name and signature of the console command. |
||
10 | * |
||
11 | * @var string |
||
12 | */ |
||
13 | protected $signature = 'user:restore |
||
14 | {value : Get user for a value (by email, id)} |
||
15 | {field? : Field to search by}'; |
||
16 | |||
17 | /** |
||
18 | * The console command description. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $description = 'Restore a user'; |
||
23 | |||
24 | /** |
||
25 | * Execute the console command. |
||
26 | */ |
||
27 | public function handle() |
||
28 | { |
||
29 | $user = $this->getUserModel(); |
||
30 | |||
31 | if (is_null($user)) { |
||
32 | $this->error('Oops, the user was not found!'); |
||
33 | return 1; |
||
34 | } |
||
35 | |||
36 | if (!method_exists($user, 'restore')) { |
||
37 | $this->error('Oops, user does not use softdelete!'); |
||
38 | return 1; |
||
39 | } |
||
40 | |||
41 | $user->restore(); |
||
42 | |||
43 | $this->info('User restored successfully!'); |
||
44 | |||
45 | return 0; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Get user model |
||
50 | * |
||
51 | * @return \Illuminate\Database\Eloquent\Model|null |
||
52 | */ |
||
53 | protected function getUserModel() |
||
54 | { |
||
55 | $value = $this->argument('value'); |
||
56 | $field = $this->argument('field'); |
||
57 | |||
58 | if ($field) { |
||
59 | return $this->user::onlyTrashed() |
||
0 ignored issues
–
show
|
|||
60 | ->where($field, $value) |
||
61 | ->first(); |
||
62 | } |
||
63 | |||
64 | return $this->user::onlyTrashed() |
||
65 | ->where('email', $value) |
||
66 | ->first() ?: $this->user::onlyTrashed()->find($value); |
||
67 | } |
||
68 | } |
||
69 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.