Laravel 路由返回 404 (Laravel 6.6.2) [英] Laravel route returns 404 (Laravel 6.6.2)

查看:141
本文介绍了Laravel 路由返回 404 (Laravel 6.6.2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多条路线,除了一条路线,每条路线都有效.即使我清除了缓存并使用

I have multiple routes where every route works except one. I keep getting a 404 page even though I cleared the cache and also checked the list of the routes with

php artisan route:list

| GET|HEAD| team/requests/{$teamId} | team_requests | App\Http\Controllers\TeamController@requests                           | web                          |

该路线出现在列表中.

我的路线是这样的

Route::get('team/requests/{$teamId}', 'TeamController@requests')->name('team_requests');

我的控制器操作如下所示:

My controller action looks like this:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TeamController extends Controller
{

    public function requests(int $teamId)
    {
        $requests = User_Team::where('team_id', $teamId)->where('isInvitation', false)->get();
        $userRequests = [];
        foreach ($requests as $request) {
            $userRequests[] = User::find($request->user_id);
        }

        return view('requests')->with('requests', $userRequests);
    }
}

我目前正在使用 laravel localhost 服务器运行网站:

I'm running the website currently with the laravel localhost server using:

php artisan serve

我想我一定在某个地方打错了,但我找不到任何东西.有人也有这个问题吗?

I think I must have a typo somewhere but I can't find anything. Does someone also had this issue?

我使用的是 Laravel 6.6.2

I'm using Laravel 6.6.2

推荐答案

感谢 lagbox 的解决方案.

Thanks for the solution from lagbox.

问题是我在路由参数的定义中使用了 $.删除它解决了问题.

The problem was that I was using $ in the defintion of the route parameter. Removing it solved the problem.

这篇关于Laravel 路由返回 404 (Laravel 6.6.2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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