pub struct Redirect { /* private fields */ }Expand description
A redirect, with a 302 Found status by default.
use laravel::http::Redirect;
async fn store() -> Redirect {
// ...
Redirect::route(users::show, 1).with("status", "User created!")
}Implementations§
Source§impl Redirect
impl Redirect
Sourcepub fn intended<H, T>(fallback: H, parameters: impl RouteParams) -> Redirectwhere
H: RouteHandler<T>,
pub fn intended<H, T>(fallback: H, parameters: impl RouteParams) -> Redirectwhere
H: RouteHandler<T>,
Redirects to the page a guest tried to visit before Authenticate
sent them to log in. Without an intended page, it redirects to fallback’s route, with
parameters given as route takes them. The session forgets the
intended page once a redirect uses it.
use laravel::http::Redirect;
async fn login() -> Redirect {
// Log the user in...
Redirect::intended(dashboard::show, ())
}§Panics
Panics outside an application context.
Source§impl Redirect
impl Redirect
Sourcepub fn with_input(self, request: &Request) -> Redirect
pub fn with_input(self, request: &Request) -> Redirect
Flash the request’s input as old input, which the next page reads with
old. Laravel leaves out the top-level password,
password_confirmation, and current_password fields, the fields given to
Errors::dont_flash, and, once the request has been
validated, every Password field at any depth, with its
confirmation.
use laravel::http::{Redirect, Request};
async fn store(request: Request) -> Redirect {
// A check of your own fails...
Redirect::back().with_input(&request)
}Source§impl Redirect
impl Redirect
Send a cookie with this response. A (name, value) pair uses the default attributes,
and a Cookie sets its own. The cookie replaces any cookie
that this response already sends with the same name, path, and domain.
use laravel::http::{Redirect, Response};
let response = Response::new("Saved").with_cookie(("theme", "dark"));
let redirect = Redirect::to("/").with_cookie(("theme", "dark"));Remove a browser cookie by sending an expired cookie. A name uses the default path and
domain. To match a custom path or domain, pass a Cookie. The
cookie values that the current request returns stay unchanged.
use laravel::http::Response;
use laravel::cookie::Cookie;
let response = Response::new("Signed out")
.without_cookie("remember")
.without_cookie(Cookie::new("tour", "").path("/admin"));Sourcepub fn with_header<K, V>(self, name: K, value: V) -> Redirect
pub fn with_header<K, V>(self, name: K, value: V) -> Redirect
Send a header with the response, replacing any header with the same name, including one the response would otherwise send:
use laravel::view::{View, view};
async fn report() -> View {
view("reports.show", ()).with_header("cache-control", "no-store")
}A name or value that isn’t a valid header turns the response into a 500 error when
the response is sent.
Sourcepub fn with_headers<K, V>(
self,
headers: impl IntoIterator<Item = (K, V)>,
) -> Redirect
pub fn with_headers<K, V>( self, headers: impl IntoIterator<Item = (K, V)>, ) -> Redirect
Send several headers with the response, such as
.with_headers([("x-one", "1"), ("x-two", "2")]). Each header replaces any header
with the same name, so when the list holds a name twice, the last value wins.
A name or value that isn’t a valid header turns the response into a 500 error when
the response is sent.
Sourcepub fn to(uri: impl Into<String>) -> Redirect
pub fn to(uri: impl Into<String>) -> Redirect
Redirect to a path or URL. If the target isn’t a valid header value, the response is a
500 instead.
Sourcepub fn status(self, status: impl IntoStatusCode) -> Redirect
pub fn status(self, status: impl IntoStatusCode) -> Redirect
Respond with the given status, as a number or a StatusCode, such as 303 for See
Other.
§Panics
Panics when the number isn’t a valid status code.
Sourcepub fn with(self, key: impl Into<String>, value: impl Serialize) -> Redirect
pub fn with(self, key: impl Into<String>, value: impl Serialize) -> Redirect
Flash data to the session along with the redirect, such as a status message for the next page.
use laravel::http::Redirect;
async fn update() -> Redirect {
// ...
Redirect::back().with("status", "Profile updated!")
}Flashing needs the session, so with is for routes in the web group. On other routes,
the redirect drops the data and logs a warning. A value that can’t be serialized as JSON
isn’t flashed and is logged as an error, as with
Session::flash.
Sourcepub fn with_query(self, query: impl Serialize) -> Redirect
pub fn with_query(self, query: impl Serialize) -> Redirect
Append query parameters to the target URL, preserving any existing query string and
fragment. Pass key-value pairs, such as [("tab", "comments")], or any Serialize
struct of single values (where None fields are omitted).
use laravel::http::Redirect;
async fn comment() -> Redirect {
// Store the comment...
Redirect::route(posts::show, 1)
.with_query([("tab", "comments")])
.with_fragment("comment-12")
}Sourcepub fn with_fragment(self, fragment: impl AsRef<str>) -> Redirect
pub fn with_fragment(self, fragment: impl AsRef<str>) -> Redirect
Add a fragment to the target URL, such as comment-12 for #comment-12, replacing any
fragment the URL already has.
use laravel::http::Redirect;
async fn comment() -> Redirect {
// Store the comment...
Redirect::route(posts::show, 1).with_fragment("comment-12")
}Source§impl Redirect
impl Redirect
Sourcepub fn route<H, T>(handler: H, parameters: impl RouteParams) -> Redirectwhere
H: RouteHandler<T>,
pub fn route<H, T>(handler: H, parameters: impl RouteParams) -> Redirectwhere
H: RouteHandler<T>,
Redirect to the route a handler handles, with parameters as route takes them.
When the URL can’t be built, such as when the handler handles no route or a parameter is
missing, the response is that error instead. The error handler reports and renders the
error as it does an error returned with ?.
§Panics
Panics outside an application context.
Source§impl Redirect
impl Redirect
Sourcepub fn with_errors(self, errors: impl Borrow<InvalidInput>) -> Redirect
pub fn with_errors(self, errors: impl Borrow<InvalidInput>) -> Redirect
Flashes validation messages to the session for the next page, where views and Inertia pages
read them as errors. Like with, it requires a session.
The messages are stored under the name of their form. Errors without
an explicit name use the request’s _form field or the validated type’s form, such as login
for a handler that took a Valid<Login> with #[validate(form = "login")]. Calling
this for two different forms flashes both sets of errors. Calling it again for the same form
replaces that form’s earlier errors.
Trait Implementations§
Source§impl IntoResponse for Redirect
impl IntoResponse for Redirect
Source§fn with_header<K, V>(self, name: K, value: V) -> Response
fn with_header<K, V>(self, name: K, value: V) -> Response
500 error.Source§fn with_headers<K, V>(
self,
headers: impl IntoIterator<Item = (K, V)>,
) -> Response
fn with_headers<K, V>( self, headers: impl IntoIterator<Item = (K, V)>, ) -> Response
500 error.Auto Trait Implementations§
impl Forget for Redirect
impl Freeze for Redirectwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
*const ArcInner<Inner> is !null: Freeze,
PhantomData<ArcInner<Inner>>: Freeze,
NonZero<u16>: Freeze,
PhantomData<(String, Value)>: Freeze,
*const [Pos] is !null: Freeze,
PhantomData<[Pos]>: Freeze,
PhantomData<Bucket<HeaderValue>>: Freeze,
PhantomData<ExtraValue<HeaderValue>>: Freeze,
impl Move for Redirect
impl RefUnwindSafe for Redirectwhere
Atomic<usize>: RefUnwindSafe,
Error: RefUnwindSafe,
NonZero<u16>: RefUnwindSafe,
Atomic<*mut ()>: RefUnwindSafe,
impl Send for Redirect
impl Sync for Redirect
impl Unpin for Redirect
impl UnsafeUnpin for Redirectwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<Inner> is !null: UnsafeUnpin,
PhantomData<ArcInner<Inner>>: UnsafeUnpin,
NonZeroU16Inner: UnsafeUnpin,
PhantomData<(String, Value)>: UnsafeUnpin,
*const [Pos] is !null: UnsafeUnpin,
PhantomData<[Pos]>: UnsafeUnpin,
PhantomData<Bucket<HeaderValue>>: UnsafeUnpin,
PhantomData<ExtraValue<HeaderValue>>: UnsafeUnpin,
impl UnwindSafe for Redirectwhere
RawVecInner: UnwindSafe,
Arc<Inner>: UnwindSafe,
NonZero<u16>: UnwindSafe,
NonNull<u8>: UnwindSafe,
BoxRaw<[Pos]>: UnwindSafe,
*const u8: UnwindSafe,
Align8<*mut ()>: UnwindSafe,
&'static Vtable: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<K> ForeignKey<K> for K
impl<K> ForeignKey<K> for K
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more