Skip to main content

Redirect

Struct Redirect 

Source
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

Source

pub fn intended<H, T>(fallback: H, parameters: impl RouteParams) -> Redirect
where 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

Source

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

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"));
Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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")
}
Source

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

pub fn permanent(self) -> Redirect

Respond with 301 Moved Permanently.

Source§

impl Redirect

Source

pub fn route<H, T>(handler: H, parameters: impl RouteParams) -> Redirect
where 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

Source

pub fn back() -> Redirect

Redirect back to the previous page. That’s the request’s Referer, or else the last page the session saw, or else the application’s URL.

§Panics

Panics outside an application context.

Source§

impl Redirect

Source

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 Debug for Redirect

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl IntoResponse for Redirect

Source§

fn into_response(self) -> Response

Turn this into a Response. Read more
Send a cookie with this response, replacing any cookie the response already sends with the same name, path, and domain. Read more
Remove a browser cookie. Pass the cookie’s name, or a Cookie with the path and domain that set it. Read more
Source§

fn with_header<K, V>(self, name: K, value: V) -> Response

Send a header with the response, replacing any header with the same name. A name or value that isn’t a valid header makes the response a 500 error.
Source§

fn with_headers<K, V>( self, headers: impl IntoIterator<Item = (K, V)>, ) -> Response

Send several headers with the response, each replacing any header with the same name. A name or value that isn’t a valid header makes the response a 500 error.

Auto Trait Implementations§

§

impl Forget for Redirect

§

impl Freeze for Redirect
where *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 Redirect

§

impl Send for Redirect
where RawVecInner: Send, Arc<Inner>: Send, NonZero<u16>: Send, RawTable<usize>: Send, BoxRaw<[Pos]>: Send, Bytes: Send,

§

impl Sync for Redirect
where RawVecInner: Sync, Arc<Inner>: Sync, NonZero<u16>: Sync, RawTable<usize>: Sync, BoxRaw<[Pos]>: Sync, Bytes: Sync,

§

impl Unpin for Redirect
where *const u8 is !null: Unpin, Arc<Inner>: Unpin, NonZero<u16>: Unpin, Box<[Pos]>: Unpin, *const u8: Unpin, Align8<*mut ()>: Unpin, &'static Vtable: Unpin,

§

impl UnsafeUnpin for Redirect
where *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 Redirect
where 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: RngExt + ?Sized, Self: FakeBase<U>,

Source§

impl<T> FillValue<Option<T>> for T
where T: Send + 'static,

Source§

async fn fill(self) -> Result<Option<T>, Error>

Resolves the column’s value. Read more
Source§

impl<T> FillValue<T> for T
where T: Send + 'static,

Source§

async fn fill(self) -> Result<T, Error>

Resolves the column’s value. Read more
Source§

impl<K> ForeignKey<K> for K

Source§

fn key(&self) -> Option<&K>

Returns the key, or None when the field holds no key.
Source§

fn __from_key(key: K) -> K

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T, N> NotifiedBy<T> for N
where T: Notification<N>,

Source§

fn __routes(&self) -> Vec<Route>

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, V> UpdateValue<T> for V
where V: FillValue<T>,

Source§

fn __update<M, U>(self, column: Column<M, T>, update: U) -> U
where M: Model, U: Updates<M>, T: IntoExpr + Clone + Send + Sync + 'static,

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more