0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Laravel】同じ部品だけど参照URLに応じてリダイレクト先を変えたい

Posted at

#やりたかったこと
画面1と画面2に同じ機能(カウント+1など)を持つ「ボタン」を置きたいけど、

  • 「URL1のボタン→URLa」
  • 「URL2のボタン→URLb」

にリダイレクトするようにしたい

#結論
ヘッダーの「referer」で解決しました

buttonControler.php
public function button(Request $request){
    //ヘッダーのreferer(参照先)取得
    $referer = $request->headers->get('referer');

    if(strpos($referer, 'URL1')){
        return redirect()->route('URLa');
    }
    if(strpos($referer, 'URL2')){
        return redirect()->route('URLb');
    }
}

#経て
こんなことかと思うかもしれませんが、1時間弱うんぬん悩んでました。。。
もしもっといい方法等あればご指摘ください!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?