1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* NOTICE OF LICENSE |
5
|
|
|
* |
6
|
|
|
* Part of the Rinvex Fort Package. |
7
|
|
|
* |
8
|
|
|
* This source file is subject to The MIT License (MIT) |
9
|
|
|
* that is bundled with this package in the LICENSE file. |
10
|
|
|
* |
11
|
|
|
* Package: Rinvex Fort Package |
12
|
|
|
* License: The MIT License (MIT) |
13
|
|
|
* Link: https://rinvex.com |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Rinvex\Fort\Console\Commands; |
17
|
|
|
|
18
|
|
|
use Illuminate\Console\Command; |
19
|
|
|
use Illuminate\Support\Facades\Lang; |
20
|
|
|
|
21
|
|
|
class UserFindCommand extends Command |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* The name and signature of the console command. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $signature = 'fort:user:find {field? : Get specific user by field}'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The console command description. |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $description = 'List matched users.'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Execute the console command. |
39
|
|
|
* |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
|
public function handle() |
43
|
|
|
{ |
44
|
|
|
$columns = ['id', 'email', 'username', 'gender', 'active', 'verified', 'created_at', 'updated_at']; |
45
|
|
|
|
46
|
|
|
// Find single user |
47
|
|
|
if ($field = $this->argument('field')) { |
48
|
|
|
if (intval($field) && $user = $this->laravel['rinvex.fort.user']->find($field, $columns)) { |
49
|
|
|
return $this->table($columns, [$user->toArray()]); |
50
|
|
|
} else if (filter_var($field, FILTER_VALIDATE_EMAIL) && $user = $this->laravel['rinvex.fort.user']->findWhere(['email' => $field], $columns)->first()) { |
|
|
|
|
51
|
|
|
return $this->table($columns, [$user->toArray()]); |
52
|
|
|
} else if ($user = $this->laravel['rinvex.fort.user']->findWhere(['username' => $field], $columns)->first()) { |
|
|
|
|
53
|
|
|
return $this->table($columns, $user->toArray()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $this->error(Lang::get('rinvex.fort::artisan.user.invalid', ['field' => $field])); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// Find multiple users |
60
|
|
|
$field = $this->anticipate(Lang::get('rinvex.fort::artisan.user.field'), ['id', 'email', 'username'], 'id'); |
61
|
|
|
$operator = $this->anticipate(Lang::get('rinvex.fort::artisan.user.operator'), ['=', '<', '>', '<=', '>=', '<>', '!=', 'like', 'like binary', 'not like', 'between', 'ilike', '&', '|', '^', '<<', '>>', 'rlike', 'regexp', 'not regexp', '~', '~*', '!~', '!~*', 'similar to', 'not similar to'], '='); |
|
|
|
|
62
|
|
|
$value = $this->ask(Lang::get('rinvex.fort::artisan.user.value')); |
63
|
|
|
$results = $this->laravel['rinvex.fort.user']->where($field, $operator, $value)->get($columns); |
64
|
|
|
|
65
|
|
|
return $this->table($columns, $results->toArray()); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.