删除一些无用if判断
This commit is contained in:
parent
c56b37667f
commit
c9ce40d34d
|
@ -6,6 +6,7 @@ use Exception;
|
|||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||
|
@ -56,6 +57,7 @@ class ExceptionReport
|
|||
TokenInvalidException::class=>['token不正确',400],
|
||||
NotFoundHttpException::class=>['没有找到该页面',404],
|
||||
MethodNotAllowedHttpException::class=>['访问方式不正确',405],
|
||||
QueryException::class=>['参数错误',401],
|
||||
];
|
||||
|
||||
public function register($className,callable $callback){
|
||||
|
|
|
@ -37,12 +37,8 @@ class AdminController extends Controller
|
|||
//用户注册
|
||||
public function store(UserRequest $request)
|
||||
{
|
||||
$admin = Admin::create($request->all());
|
||||
if ($admin) {
|
||||
return $this->setStatusCode(201)->success('用户注册成功');
|
||||
}
|
||||
return $this->failed('用户注册失败');
|
||||
|
||||
Admin::create($request->all());
|
||||
return $this->setStatusCode(201)->success('用户注册成功');
|
||||
}
|
||||
|
||||
//用户登录
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api;
|
|||
use App\Http\Requests\Api\UserRequest;
|
||||
use App\Http\Resources\Api\UserResource;
|
||||
use App\Jobs\Api\SaveLastTokenJob;
|
||||
use App\Models\Book;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
@ -30,12 +31,8 @@ class UserController extends Controller
|
|||
}
|
||||
//用户注册
|
||||
public function store(UserRequest $request){
|
||||
$user = User::create($request->all());
|
||||
if($user){
|
||||
return $this->setStatusCode(201)->success('用户注册成功');
|
||||
}
|
||||
return $this->failed('用户注册失败');
|
||||
|
||||
User::create($request->all());
|
||||
return $this->setStatusCode(201)->success('用户注册成功');
|
||||
}
|
||||
//用户登录
|
||||
public function login(Request $request){
|
||||
|
@ -61,13 +58,4 @@ class UserController extends Controller
|
|||
Auth::logout();
|
||||
return $this->success('退出成功...');
|
||||
}
|
||||
public function test(Request $request){
|
||||
$token = Auth::guard('api')->getToken();
|
||||
$token = Auth::guard('admin')->setToken($token)->refresh();
|
||||
dd(Auth::guard('admin')->setToken($token)->check());
|
||||
|
||||
return $token;
|
||||
$token = Auth::guard('api')->getToken();
|
||||
Auth::guard('api')->setToken($token)->invalidate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,4 +51,7 @@ class User extends Authenticatable implements JWTSubject
|
|||
{
|
||||
$this->attributes['password'] = bcrypt($value);
|
||||
}
|
||||
public function books(){
|
||||
return $this->hasMany(Book::class,'user_id','id')->limit(2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ use Illuminate\Http\Request;
|
|||
*/
|
||||
|
||||
Route::namespace('Api')->prefix('v1')->middleware('cors')->group(function () {
|
||||
Route::get('/test', 'UserController@test')->name('users.test');
|
||||
Route::middleware('api.guard')->group(function () {
|
||||
//用户注册
|
||||
Route::post('/users', 'UserController@store')->name('users.store');
|
||||
|
|
Loading…
Reference in New Issue