【问题标题】:How to redirect to a url in laravel without adding base url to it?如何在不添加基本 url 的情况下重定向到 laravel 中的 url?
【发布时间】:2018-09-24 16:20:04
【问题描述】:

在 Laravel 中使用 route('/index',[],false),通过将第三个参数设置为 url 我们得到相对路径。但是当我使用 Redirect::intended('/dashboard') 那么如何获取相对路径。现在它正在将 /dashboard 添加到 BASE_URL

【问题讨论】:

    标签: php laravel


    【解决方案1】:
    Redirects
    // Redirect to url
    redirect('itsolution');
    // Redirect to url with data
    redirect('itsolution')->with('key', 'value');
    // Redirect to url with input data
    redirect('itsolution')->withInput(Input::get());
    // Redirect to url with error
    redirect('itsolution')->withErrors($validator);
    // Redirect to back url
    back()->withInput();
    
    // Redirect to route url 
    redirect()->route('login');
    // For a route with the following URI: view/{id}
    redirect()->route('view', ['id' => 1]);
    // For a route with the following URI: view/{id}/edit/{id_sub}
    redirect()->route('profile', [$user]);
    
    // Redirect to controller method
    redirect()->action('HomeController@index');
    // Redirect to controller method with argument
    redirect()->action('UserController@profile', ['id' => 1]);
    // Response macro
    response()->caps('foo');
    // Redirect intend url
    redirect()->intended('dashboard');
    // Redirect back url
    redirect()->back();
    

    【讨论】:

    • 欢迎来到 SO。通过一些关于他们如何回答问题的解释来改进仅代码的答案。
    猜你喜欢
    • 2020-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-16
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    相关资源
    最近更新 更多