Clean up binders.

This commit is contained in:
James Cole
2018-01-10 07:51:47 +01:00
parent c045193246
commit 48c16c3dcc
3 changed files with 43 additions and 16 deletions

View File

@@ -32,6 +32,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Log;
use Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class User.
@@ -60,6 +61,23 @@ class User extends Authenticatable
*/
protected $table = 'users';
/**
* @param string $value
*
* @return User
*/
public static function routeBinder(string $value): User
{
if (auth()->check()) {
$userId = intval($value);
$user = self::find($userId);
if (!is_null($user)) {
return $user;
}
}
throw new NotFoundHttpException;
}
/**
* @codeCoverageIgnore
* Link to accounts.