dougu6815
dougu6815
2019-03-04 11:04

如何在Laravel中重定向并在模式中显示信息

I have list of notifications in a table and with a button beside it to view the recipients in a modal. Here's what I have done:

notification.blade.php

<div class="recipient_modal">
    <div class="apply_box">
        <div class="rec_close">
            <img src="../../assets/images/close.png" alt="close">
        </div>
        {{-- loop for recipients --}}
    </div>
</div>


<div class="recipients">
     <a class="btn pink rec_btn" href="{{ url('/recipients', 1) }}">Recipients</a>
</div>

web.php

Route::get('/recipients/{news}', 'Admin\NotificationController@recipients');

NotificationController.php

public function recipients()
{
    $messageOne = ['6','7','8'];

    $news = News::with('contest');
    $received = $news->whereIn('message_one', $messageOne)->orderBy('created_at', 'desc')->paginate(15);

    return Redirect::back()->with(['received'=>$received ]);
}

But the problem for this one, it returns Page not Found error. I'm trying to display the recipients information in a modal and I don't have idea for this one. Should I use ajax and how to do it?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • dssnh86244 dssnh86244 2年前

    I would suggest using ajax since you are working on a modal. redirect back would definitely refresh the page. With ajax you can get the response in JS and handle it properly. Thanks and goodluck

    点赞 评论 复制链接分享
  • drnpwmq4536 drnpwmq4536 2年前
    Route::get('/recipients/{news}', 'Admin\NotificationController@recipients');
    

    Because in the above line you had passed a parameter and in your controller file the method name does not have any parameter, your method should be like

    public function recipients($news)
    {
      $messageOne = ['6','7','8'];
    
      $news = News::with('contest');
      $received = $news->whereIn('message_one', $messageOne)->orderBy('created_at', 'desc')->paginate(15);
    
      return Redirect::back()->with(['received'=>$received ]);
    }
    
    点赞 评论 复制链接分享

相关推荐