doubishi8303 2014-08-19 18:29
浏览 5

too long

Maybe I'm missing something but I can't figure out how to do this.

I have a index view that lists all the records from my tiers table. The page has a "Create New Tier" button that displays a form. The user enters the data for the new tier and hits the submit button. In my TierController I have the following:

public function store()
{
//
$data = Input::all();

$tier = new Tier();
$tier->name=$data['name'];
$tier->price = $data['price'];

$tier->save();

return Redirect::back()->with('message',"Tier created successfully.");
}

This takes me back to the empty create form and displays the message but the user has to press the back button to return to the index view which doesn't show the new data until I hit refresh. I would like to have the system automatically return to the index view after the submit button is clicked with the refreshed data.

I know that I can do a Redirect::to('tiers.index')->with('message','Tier created successfully') but the problem I have with that is then the browser history looks like

tier.index -> tier.create -> tier.index

This then is very confusing for the user when they do hit the back button as the create view shows up and freaks them out.

Is there a way to do a Redirect::back (or something) that would not leave the tier.create view in the history and also refresh the index data?

Thanks

  • 写回答

1条回答 默认 最新

  • dongmengan8620 2014-08-19 20:51
    关注

    I don't think you can manipulate the user's browsing history without resorting to Javascript or something. Certainly not with Laravel alone. So, don't. You're overthinking this. Why do you care so much about what's in the browser's history? And why would you want to manipulate it so that it doesn't reflect the pages the user actually went through? It sort of defeats the purpose of having a history...

    If your app's navigation is sufficiently intuitive and familiar, the user won't feel the need to use the native browser's back / forward buttons. Don't assume your users will make the most basic browsing mistakes unless you have data to back that up.

    Having said that, conventions don't give you much choice in this matter: generally you either lead the user back to the index -- i.e. Redirect::route('tiers.index') -- or to the newly created item -- i.e. Redirect::route('tiers.show', $tier->id). Both are perfectly acceptable and surely within the user's expected outcome.

    If tiers are something the user can only add within certain limits (one per user, one per category, once a day, etc), then I'd attempt to redirect him away from the create page, preventing him from filling out a fresh form which won't ever pass validation. Otherwise, chose one of the pages above and move on to your next development challenge.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角