メール送信　boiler



```php
//App/Http/Controllers/Frontend/Auth/Authcontroller.php
・
・
・
public function __construct(AuthenticationContract $auth)
{
	$this->auth = $auth;
}

・
・
・

public function confirmAccount($token) {
	//Don't know why the exception handler is not catching this
	try {
		$this->auth->confirmAccount($token);
		return redirect()->route('frontend.dashboard')->withFlashSuccess("Your account has been successfully confirmed!");
	} catch (GeneralException $e) {
		return redirect()->back()->withInput()->withFlashDanger($e->getMessage());
	}
}
・
・
・
```

```php
//App/Providers/AccessServiceProvider.php
・
・
・
public function registerBindings() {
	$this->app->bind(
		'App\Repositories\Frontend\Auth\AuthenticationContract',
		'App\Repositories\Frontend\Auth\EloquentAuthenticationRepository'
	);

	$this->app->bind(
		'App\Repositories\Frontend\User\UserContract',
		'App\Repositories\Frontend\User\EloquentUserRepository'
	);

	$this->app->bind(
		'App\Repositories\Backend\User\UserContract',
		'App\Repositories\Backend\User\EloquentUserRepository'
	);

	$this->app->bind(
		'App\Repositories\Backend\Role\RoleRepositoryContract',
		'App\Repositories\Backend\Role\EloquentRoleRepository'
	);

	$this->app->bind(
		'App\Repositories\Backend\Permission\PermissionRepositoryContract',
		'App\Repositories\Backend\Permission\EloquentPermissionRepository'
	);
}
・
・
・
```

AuthControllerはApp/Repositories/Frontend/Auth/EloquentAuthenticationRepository.phpのインスタンスを $auth として受け取っていることがわかる

```php
//App/Repositories/Frontend/Auth/EloquentAuthenticationRepository.php
・
・
・
use App\Repositories\Frontend\User\UserContract;
・
・
・
public function __construct(Socialite $socialite, Guard $auth, UserContract $users) {
	$this->socialite = $socialite;
	$this->users = $users;
	$this->auth = $auth;
}
・
・
・
public function confirmAccount($token) {
	return $this->users->confirmAccount($token);
}

public function resendConfirmationEmail($user_id) {
	return $this->users->sendConfirmationEmail($user_id);
}
・
・
・
```

EloquentAuthenticationRepository.phpは $users としてApp/Repositories/Frontend/User/EloquentUserRepository.phpのインスタンスを受け取っている

```php
//App/Repositories/Frontend/User/EloquentUserRepository.php

public function confirmAccount($token) {
	$user = User::where('confirmation_code', $token)->first();

	if ($user) {
		if ($user->confirmed == 1)
			throw new GeneralException("Your account is already confirmed.");

		if ($user->confirmation_code == $token) {
			$user->confirmed = 1;
			return $user->save();
		}

		throw new GeneralException("Your confirmation code does not match.");
	}

	throw new GeneralException("That confirmation code does not exist.");
}

	/**
	 * @param $user
	 * @return mixed
	 */
public function sendConfirmationEmail($user) {
	//$user can be user instance or id
	if (! $user instanceof User)
		$user = User::findOrFail($user);

	return Mail::send('emails.confirm', ['token' => $user->confirmation_code], function($message) use ($user)
	{
		$message->to($user->email, $user->name)->subject(app_name().': Confirm your account!');
	});
}
```

メールアドレスのアクティベート関連の記述はここで行うこととなる
以下に関連するルーティングを示しておく
それぞれ　user_id　または　token　を　URLより受け取り処理したのちにリダイレクトを行っている

GET|HEAD | account/confirm/resend/{user_id} | account.confirm.resend  | App\Http\Controllers\Frontend\Auth\AuthController@resendConfirmationEmail
GET|HEAD | account/confirm/{token}          | account.confirm         | App\Http\Controllers\Frontend\Auth\AuthController@confirmAccount



use App\Repositories\Frontend\Auth\AuthenticationContract;
ここで設定