Skip to content

Commit

Permalink
switch to service provider and add config
Browse files Browse the repository at this point in the history
  • Loading branch information
amosmos committed Aug 23, 2017
1 parent 3421d5d commit 986b42d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
],
"require": {
"php": "^7.0",
"illuminate/console": "^5.3.28",
"illuminate/events": "^5.3.28"
"illuminate/console": "^5.3.23",
"illuminate/support": "^5.3.23"
},
"autoload": {
"psr-4": {
Expand Down
8 changes: 6 additions & 2 deletions src/Commands/CreateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace BOAIdeas\CreateUser\Commands;

use App\User;
use Illuminate\Console\Command;

class CreateUser extends Command
Expand Down Expand Up @@ -32,11 +31,16 @@ public function handle()
$email = $this->ask('User email');
$password = $this->ask('User password');

User::create([
$model = config('createuser.model');

$user = new $model;

$model::fill([
'name' => $name,
'email' => $email,
'password' => bcrypt($password),
]);

$this->info('New user created!');
}
}
4 changes: 4 additions & 0 deletions src/Config/createuser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
return [
'model' => 'App\User'
];
31 changes: 31 additions & 0 deletions src/CreateUserServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace BOAIdeas\CreateUser;

use Illuminate\Support\ServiceProvider;

class CreateUserServiceProvider extends ServiceProvider
{
public function boot()
{
$this->publishes([
__DIR__.'/Config/createuser.php' => config_path('createuser.php'),
]);
}

/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/Config/createuser.php', 'createuser'
);

$this->commands([
Commands\CreateUser::class,
]);
}
}

0 comments on commit 986b42d

Please sign in to comment.