Symfony\Component\HttpKernel\Exception\NotFoundHttpException - Laravel API [英] Symfony\Component\HttpKernel\Exception\NotFoundHttpException - Laravel API

查看:215
本文介绍了Symfony\Component\HttpKernel\Exception\NotFoundHttpException - Laravel API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用 url http://127.0.0.1:8000/api/auth/upload 在 postman 中访问以下 API 时,我收到错误 Symfony\\组件\\HttpKernel\\Exception\\NotFoundHttpException .有什么关于我错在哪里的猜测吗?

when trying to access the below API in postman with the url http://127.0.0.1:8000/api/auth/upload , i'm getting the error Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException . Are there any guessses about where i'm wrong?

控制器

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Files;
use Illuminate\Support\Facades\Auth;

class FileController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth:api');
    }
    public function upload(Request $req)
    {
      //
    }
}

routes/api.php

<?php
use App\Http\Controllers\FileController; 

Route::group([
    'namespace'=>'App\Http\Controllers',
    'middleware' => 'api',
    'prefix' => 'auth'

], function ($router) {
    Route::post('upload', 'FileController@upload');
});

推荐答案

由于使用了 api.php 文件,所以可以减少使用的组

Since you are using the file api.php, you can reduce the group you're using

(你也不需要使用)

<?php

Route::group(['prefix' => 'auth'], function ($router) {
    Route::post('upload', 'FileController@upload');
});

正如你在 app/Providers/RouteServiceProvider.php@40 中看到的,它已经定义了

As you can see in app/Providers/RouteServiceProvider.php@40, it is already defined

// protected $namespace = 'App\\Http\\Controllers';
//...
        $this->routes(function () {
            Route::prefix('api')
                ->middleware('api')
                ->namespace($this->namespace)
                ->group(base_path('routes/api.php'));

您是否将请求作为 POST 运行?

Did you run the request as POST ?

这篇关于Symfony\Component\HttpKernel\Exception\NotFoundHttpException - Laravel API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆