为什么我的路由莫名其妙

我按照教程写了个路由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呢

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

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 格式的数据了

2年前 评论
wongvio (楼主) 2年前
wongvio (楼主) 2年前
讨论数量: 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 格式的数据了

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

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

2年前 评论

表单验证失败了锕

2年前 评论

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