Laravel找不到路径404

Laravel can't find a path 404

所以我的路线:

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(['namespace' => 'Api'], 函数 () { 检查您的路由和控制器的命名空间是否相同,并检查您的路由是否有任何前缀。 如果以上都正确,检查app/provider/RouteServiceProvider.php

它应该是这样的:

命名空间App\Providers;

使用Illuminate\Support\Facades\Route; 使用 Illuminate\Foundation\Support\Providers\RouteServiceProvider 作为服务提供商;

class RouteServiceProvider 扩展了 ServiceProvider { /** * 此命名空间应用于您的控制器路由。 * * 此外,它被设置为 URL 生成器的根命名空间。 * * @var 字符串 */ 受保护的 $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'));
}

}