当我在Controller Method中使用Request验证时,会返回此错误:
Container.php第776行中的ReflectionException:类guest虚拟机不存在
我的请求文件如下:
<?php namespace App\Http\Requests;
use App\Http\Requests\Request;
class LoginFormRequest extends Request {
public function authorize()
{
return true;
}
public function rules()
{
switch($this->method())
{
case 'GET':
case 'DELETE':
{
return [];
}
case 'POST':
{
return [
"name" => "required|alpha_num|min:3",
"email" => "required|email",
"password" => "required|min:6|confirm",
"password_confirmation" => "required",
"gender" => "required",
"birthday" => "required",
];
}
case 'PUT':
case 'PATCH':
{
return [
];
}
default:
return [];
break;
}
}
}
我的控制器如下:
<?php namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\LoginFormRequest;
use Request;
use App\Models\AppUser as AppUser;
class LoginController extends Controller {
protected $pass_key = "some_key";
public function check()
{
...
}
public function store(LoginFormRequest $request)
{
$data = Request::all();
$data['password'] = md5($this->pass_key.$data['password']);
$app_user = AppUser::create($data);
return response()->json([
'success' => true,
'message' => 'Bem vindo(a)!',
'app_user' => $app_user
]);
}
}
我的请求是路由 api / register 调用的商店方法。
$router->group(['middleware' => 'Api'], function() {
Route::post('api/login', ['as' => 'api.login', 'uses' => 'Api\LoginController@check']);
Route::post('api/register', ['as' => 'api.register', 'uses' => 'Api\LoginController@store']);
});
当我在POST规则中删除数组的索引时,显示错误。
有人可以帮助我吗?
答案 0 :(得分:2)
在您的请求文件中
use Illuminate\Http\Request
因为您的类LoginFormRequest在Laravel中扩展了Request。你应该。 在您的控制器中
$data = LoginFormRequest::all();