Skip to content

Instantly share code, notes, and snippets.

@Anahkiasen
Last active September 18, 2015 15:02
Show Gist options
  • Save Anahkiasen/ea7dc2dc497d91206590 to your computer and use it in GitHub Desktop.
Save Anahkiasen/ea7dc2dc497d91206590 to your computer and use it in GitHub Desktop.
<?php
namespace Forge\Commands\Commands\Users;
use Forge\Commands\Command;
use Forge\Commands\Commands\AbstractCommand;
use Forge\Entities\Models\User;
use Illuminate\Contracts\Bus\SelfHandling;
class RegisterCommand extends AbstractCommand implements SelfHandling
{
/**
* @var string
*/
private $email;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $password;
/**
* Create a new command instance.
*
* @param string $name
* @param string $email
* @param string $password
*/
public function __construct($name, $email, $password)
{
$this->email = $email;
$this->name = $name;
$this->password = $password;
}
/**
* Execute the command.
*
* @return User
*/
public function handle()
{
return User::create([
'name' => $this->name,
'email' => $this->email,
'password' => $this->password,
]);
}
}
<?php
namespace Forge\Http\Requests;
class RegisterRequest extends AbstractRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
'email' => 'required|unique:users',
'password' => 'required|confirmed',
];
}
}
<?php
namespace Forge\Http\Controllers;
/**
* @Middleware("auth")
* @Controller(prefix="users")
* @Resource("users", only={"index", "store", "show"})
*/
class UsersController extends AbstractController
{
/**
* @param RegisterRequest $request
* @param Guard $auth
*
* @return RedirectResponse
*/
public function store(RegisterRequest $request, Guard $auth)
{
// Create and authenticate user
$user = $this->dispatchFrom(RegisterCommand::class, $request);
$auth->login($user);
return Redirect::route('search');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment