diff --git a/app/Console/Commands/AddBalance.php b/app/Console/Commands/AddBalance.php new file mode 100644 index 0000000..59ea4f7 --- /dev/null +++ b/app/Console/Commands/AddBalance.php @@ -0,0 +1,45 @@ +argument('balance'); + $id = (int) $this->argument('id'); + if ($balance == 0 || $id == 0) { + $this->fail('Balance or Id must be non zero value!'); + } + + /** @var User */ + $user = User::find([ 'id' => $id ])->firstOrFail(); + $user->balance += $balance; + $user->save(); + + $name = $user->name; + $balance = $user->balance; + + $this->info("User $name has $balance balance now"); + } +} diff --git a/app/Console/Commands/MakeUser.php b/app/Console/Commands/MakeUser.php new file mode 100644 index 0000000..619600b --- /dev/null +++ b/app/Console/Commands/MakeUser.php @@ -0,0 +1,38 @@ +argument('name'); + $user = new User(); + $user->name = $name; + $user->save(); + $id = $user->id; + $this->info("Created user with id $id"); + } +} diff --git a/app/Console/Commands/ShowUsers.php b/app/Console/Commands/ShowUsers.php new file mode 100644 index 0000000..8303268 --- /dev/null +++ b/app/Console/Commands/ShowUsers.php @@ -0,0 +1,40 @@ +argument('page'); + $users = User::all()->forPage($page, 20)->all(); + + $this->info("Listing all users for page $page"); + $this->info("Id\tName\tBalance"); + foreach ($users as $user) { + $this->info($user->id . ":\t" . $user->name . "\t" . $user->balance); + } + } +}