laravel 8, laravel 9, laravel 10 and laravel 11. Laravel version provided redirect(). there are several way to do redirect URL in Laravel. In this post i am going to give you all the way to redirect URL with parameters.
return redirect()->route('login');If your route has parameters, you may pass them as the second argument to the route method:// For a route with the following URI: profile/{id} return redirect()->route('profile', ['id' => 1]);...
with()方法允许我们将数据从控制器传递到视图。这个方法接受两个参数。第一个参数是将在视图中创建的变量的名称。第二个参数将是该变量的值。 总结一下,我们已经查询了数据库中的所有用户,并将它们作为User对象数组传递给了视图。由于users是with()方法的第一个参数,所以User对象数组将在视图中作为变量$users可用。
1return redirect()->route('login');If your route has parameters, you may pass them as the second argument to the route method:1// For a route with the following URI: profile/{id} 2 3return redirect()->route('profile', ['id' => 1]);...
When you call the redirect helper with no parameters, an instance of Illuminate\Routing\Redirector is returned, allowing you to call any method on the Redirector instance. For example, to generate a RedirectResponse to a named route, you may use the route method:...
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, ]; protected $bootstrappers = [ \Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables::class, \Illuminate\Foundation\Bootstrap\LoadConfiguration::class, ...
return Redirect::to('profile/user'); });\ 3. In routes.php, create our route group: Route::group(array('before' => 'checkUser', 'prefix' => 'profile'), function() { Route::get('user', function() { return 'I am logged in! This is my user ...
上文说过,Application中register()会调用service provider中的register()方法,看下\Illuminate\Routing\RoutingServiceProvider源码就发现其注册了几个service:'router', 'url', 'redirect', PsrHttpMessage|ServerRequestInterface::class, PsrHttpMessageResponseInterface::class, IlluminateContractsRoutingResponseFactory::...
// When there are other custom process configurations 'processes' => [ 'test' => [ 'class' => \App\Processes\TestProcess::class, 'redirect' => false, 'pipe' => 1, ], // ... ] + Hhxsv5\LaravelS\Components\Apollo\Process::getDefinition(), List of available parameters.Parameter...
redirect('dashboard')->with('status', 'Profile updated!');重定向并使用with方法将数据闪存在 Session 中, redirect()->route('profile', [$user]); //通过 Eloquent 模型填充参数 1. 2. 3. 4. 5. 6. 如果要自定义路由参数中的值,那么应该覆盖 Eloquent 模型里面的 getRouteKey 方法: ...