为什么我的路由莫名其妙

我按照教程写了个路由routes\api.php

<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::prefix('v1')->namespace('Api')->name('api.v1')->group(function() {

    // 短信验证码
    Route::post('verificationCodes', 'VerificationCodesController@store')
        ->name('verificationCodes.store');
});

用户访问http://xxxx.com/api/v1/verificationCodes然后就开始执行下面的程序,没错吧

<?php

namespace App\Http\Controllers\Api;

use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Overtrue\EasySms\EasySms;
use App\Http\Requests\Api\VerificationCodeRequest;

class VerificationCodesController extends Controller
{
    public function store(VerificationCodeRequest $request, EasySms $easySms)
    {
        $phone = $request->phone;
        .
        .
        .
    }
}

但是,这个时候,用postman看,就给我返回了一堆html,然后在chrome里看这些html就是laravel的默认首页,我路由没有写这些东西啊,也不报错,就很奇怪。

然后我检查了app\Http\Request\Api\ VerificationCodeRequest这个文件,里面也没写什么啊

<?php

namespace App\Http\Requests\Api;

class VerificationCodeRequest extends FormRequest
{
    public function rules()
    {
        return [
            'phone' => 'required|phone:CN,mobile|unique:users',
        ];
    }
}

为什么会返回首页的html呢

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
最佳答案

Nginx配置加这个 location 了吗:

server {
    listen      80;
    server_name localhost;
    root        /var/www/joker/public;
    index       index.html index.htm index.php;
    # 这里的匹配规则
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
}

另外,在你的 postman 的 Header 中加入 Accept : application/json 就会返回 json 格式的数据了

4年前 评论
wongvio (楼主) 4年前
wongvio (楼主) 4年前
讨论数量: 3

Nginx配置加这个 location 了吗:

server {
    listen      80;
    server_name localhost;
    root        /var/www/joker/public;
    index       index.html index.htm index.php;
    # 这里的匹配规则
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
}

另外,在你的 postman 的 Header 中加入 Accept : application/json 就会返回 json 格式的数据了

4年前 评论
wongvio (楼主) 4年前
wongvio (楼主) 4年前

laravel的Request 验证失败会跳转首页 :joy:

4年前 评论

表单验证失败了锕

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!