3 namespace BookStack\Console\Commands;
5 use BookStack\Users\Models\User;
7 use Illuminate\Console\Command;
12 trait HandlesSingleUser
15 * Fetch a user provided to this command.
16 * Expects the command to accept 'id' and 'email' options.
19 private function fetchProvidedUser(): User
21 $id = $this->option('id');
22 $email = $this->option('email');
23 if (!$id && !$email) {
24 throw new Exception("Either a --id=<number> or --email=<email> option must be provided.\nRun this command with `--help` to show more options.");
27 $field = $id ? 'id' : 'email';
28 $value = $id ?: $email;
31 ->where($field, '=', $value)
35 throw new Exception("A user where {$field}={$value} could not be found.");