针对不同按钮在不同页面上重定向(Laravel 5.3)

时间:2016-10-31 08:49:58

标签: php laravel laravel-5.3

这是我的观点我有2个按钮,一个是保存并退出,另一个是保存并留在这里

查看

<button type="submit" name="submit_1"> Submit and Exit</button>
<button type="submit" name="submit_2">save and stay Here</button>

控制器

public function store(Request $request)
    {


        $data['name']             = $request->input('name');
        $data['adr']            = $request->input('adr');

         $myuser = Data::create($data);
          if(Input::get('submit_1')) {
            return redirect()->route('myuser.index');
        } elseif(Input::get('submit_2')) {
            return redirect()->route('myuser.create');
        }
    }

我试过这个,但它不适合我,请帮助我

2 个答案:

答案 0 :(得分:1)

你可以尝试:

<input type='submit' name='submit' value='submit_1'>
<input type='submit' name='submit' value='submit_2'>

答案 1 :(得分:0)

试试这个:

查看

<button type="submit" name="submit_1" value="submit_1"> Submit and Exit</button>
<button type="submit" name="submit_2" value="submit_2">save and stay Here</button>

<强>控制器

public function store(Request $request)
    {
        if($request->get('submit_1') == "submit_1") {
            return redirect()->route('myuser.index');
        } else if($request->get('submit_2') == "submit_2") {
            return redirect()->route('myuser.create');            
        }
    }