[英]ReflectionException Class UserController does not exist Laravel5.4
Everytime i hit the Submit Button i got this problem ReflectionException Class UserController does not exist 每次我按下Submit按钮时,我都会遇到此问题ReflectionException类UserController不存在
<?php
namespace app\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class UserController extends Controller {
public function postSignUp(Request $request)
{
$email = $request['email'];
$first_name = $request['first_name'];
$password = bcrypt($request['password']);
$user = new User();
$user->email =$email;
$user->first_name=$first_name;
$user->password = $password;
$user->save();
return redirect()->back();
}
public function postSignIn(Request $request)
{
}
}
My route file: 我的路线文件:
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* This namespace is applied to your controller routes.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
//
parent::boot();
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
//
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
Route::post('/signup',[
'uses'=>'UserController@postSignUp',
'as'=>'signup'
]);
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
}
You use invalid namespace. 您使用无效的名称空间。 Instead of: 代替:
namespace app\Http\Controllers;
in your UserController you should use: 在您的UserController中,您应该使用:
namespace App\Http\Controllers;
namespace App\Http\Controllers;
use Illuminate\Http\Request;
Use namespace
like that and try command php artisan route:cache
使用这样的namespace
,然后尝试命令php artisan route:cache
and php artisan route:clear
和php artisan route:clear
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.