所以我的路线:
Route::match(array('GET', 'POST'),'object/create', 'ObjectController@create');
和ObjectController处理程序 - >
class ObjectController extends Controller
{
public function create(Request $request){
$fieldNames = array(
.
.
.
);
$validator = Validator::make($request->all(), $rules);
$validator->setAttributeNames($fieldNames);
if ($validator->fails())
{
return back()->withErrors($validator)->withInput();
}
else
{
.
.
.
}
当我尝试访问www.xxx.com/object/create时,它给出了一个404,无法找到任何想法?我是laravel的新手。谢谢。
在Laravel中,www.xxx.com / object / create只有在Routes / web.php中定义了路由时才能工作,你也可以使用route-group Route :: group为这个路由命名空间(['namespace'] =>'Api'],function(){检查路由和控制器的命名空间是否相同,并检查您的路由是否有任何前缀。如果以上所有都正确,请检查app / provider / RouteServiceProvider.php
它应该是这样的:
命名空间App \ Providers;
使用Illuminate \ Support \ Facades \ Route;使用Illuminate \ Foundation \ Support \ Providers \ RouteServiceProvider作为ServiceProvider;
class RouteServiceProvider扩展ServiceProvider {/ ** *此命名空间应用于控制器路由。 * *此外,它被设置为URL生成器的根命名空间。 * * @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'));
}
/**
* 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'));
}
}