php - 如何在 Laravel 中进行简单的重定向?
问题描述
我正在使用 Laravel 构建我的作品集。我在构建我的投资组合的过程中学习 Laravel,所以我对它很陌生。
我正在尝试使用Route
.
这是我在web.php中写的:
Route::patch('developer-profile',[
'as' => 'developer-profile',
'uses' => 'redirectionLinks@pleaseRedirect'
]);
这就是我编写 HTML 的方式(它是刀片式的):
<a href="{{ route('developer-profile') }}">Developer Profile</a>
这就是我的控制器的样子 - Redirection.php:
namespace app\Http\Controllers;
use app\Http\Controllers\Controller;
public class redirectionLinks extends Controller{
protected $guard = 'web'; //I am not using it anywhere, but I am searching for anything that I might have missed.
public function pleaseRedirect(){
return redirect('developer/developer-profile');
}
};
我浏览了 Laravel 的以下文档链接:
在过去的几天里还有一些我找不到链接。
我在这里遗漏了什么吗,因为我似乎从基本功能开始尝试了 5-10 种基本方法,如下所示:
Route::get('/developer/developer-profile', function(){
return view('developer/developer-profile');
})->name('developer-profile');
编辑:
当我点击php artisan route:list
CMD 时,我得到以下错误窗口:
更新:
我已将文件名更改为redirectionLinks.php
from Redirection.php
。现在,当我点击显示所有路线时出现上述错误php artisan route:list
,但仍然没有发生重定向,因为我收到以下错误:
如果有人知道我在问什么,请帮助我解决我的问题。
提前致谢。
解决方案
您必须将文件重命名为,redirectionsLinks.php
而不是Redirection.php
,如果这仍然不起作用,请尝试重建 autoload: composer dumpauto
。
无论是这样做还是在路由中执行此操作,并将您的类重命名为 Redirection,都应该有效:
Route::get('developer-profile',[
'as' => 'developer-profile',
'uses' => 'Redirection@pleaseRedirect'
]);
推荐阅读
- c# - 可空性分析无法对来自 NameValueCollection 的空值发出警告。为什么?
- json - 如何从控制器将嵌套地图呈现为 JSON
- c++ - C ++如何根据第一个,然后是第二个,然后是第三个对元组进行排序
- bem - 如何为具有相同 html 结构的块设置样式?
- python - 如何从字典列表中提取数据到熊猫数据框中?
- javascript - 如何使用 JS 在按钮单击时显示不同的 div?
- r - 如果它们不与 dplyr 不相交,如何合并两个不同的分组
- visual-studio-code - 保存时运行扩展命令
- reactjs - 根据 HTML 标签设置 i18next 语言
- python - 如何将 Python3 请求中的数据传递给 VMware 工作站 api?