Php 如何在Laravel中进行简单重定向?
我正在使用Laravel构建我的投资组合。我在建立我的投资组合的过程中学习Laravel,所以我对它非常陌生 我正在尝试使用Php 如何在Laravel中进行简单重定向?,php,laravel,controller,routes,url-redirection,Php,Laravel,Controller,Routes,Url Redirection,我正在使用Laravel构建我的投资组合。我在建立我的投资组合的过程中学习Laravel,所以我对它非常陌生 我正在尝试使用Route执行一个简单的重定向 这是我在web.php中写的: Route::patch('developer-profile',[ 'as' => 'developer-profile', 'uses' => 'redirectionLinks@pleaseRedirect' ]); namespace app\Http\Controller
Route
执行一个简单的重定向
这是我在web.php中写的:
Route::patch('developer-profile',[
'as' => 'developer-profile',
'uses' => 'redirectionLinks@pleaseRedirect'
]);
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');
}
};
这就是我编写HTML的方式(它是刀片式的):
我试着搜索和提问,但没有真正的帮助
我已经浏览了Laravel的以下文档链接:
在过去的几天里,还有一些我找不到的链接
我是否遗漏了什么,因为我似乎已经尝试了5-10种基本方法,从基本功能开始,如下所示:
Route::get('/developer/developer-profile', function(){
return view('developer/developer-profile');
})->name('developer-profile');
编辑:
当我在CMD中点击php-artisan-route:list
时,我得到以下错误窗口:
更新:
我已将文件名从Redirection.php
更改为redirectionLinks.php
。现在,当我点击php artisan route:list时出现上述错误,显示所有路由,但重定向仍然没有发生,因为我遇到以下错误:
如果有人对我的问题有所了解,请帮助我解决问题
提前感谢。您必须将文件重命名为
redirectionsLinks.php
而不是Redirection.php
,如果这仍然不起作用,请尝试重建自动加载:composer dumpauto
这样做或在路由中执行此操作,并将类重命名为重定向,都应该有效:
Route::get('developer-profile',[
'as' => 'developer-profile',
'uses' => 'Redirection@pleaseRedirect'
]);
非常感谢,成功了。我认为这个问题很小,因为我不熟悉Laravel语法。现在当我点击
php artisan route:list
时,我可以看到更新的路由,但仍然有一个错误说Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
使用get方法而不是patch,你为什么要用补丁?GET用于检索,POST用于发送。DELETE和PUT(与PATCH相同),与post一样工作,但是你必须发送一些隐藏字段,我不记得名字了,因为我已经使用javascript很久了…非常感谢,它工作了,我认为PATCH
是从我尝试各种可能的方法来检查我在这里写错了什么的时候开始的。是的,post,PUT/PATCH和DELETE用于发送表单,而不是查询应该始终获取的URL
Route::get('developer-profile',[
'as' => 'developer-profile',
'uses' => 'Redirection@pleaseRedirect'
]);