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

时间:2019-03-04 11:04:14

标签: php laravel laravel-blade

我在表格中有通知列表,旁边有一个按钮,用于查看模式中的收件人。这是我所做的:

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 ]);
}

但是对于这个问题,它返回Page Not Found错误。我正在尝试以一种模式显示收件人信息,对此我一无所知。我应该使用ajax及其用法吗?

2 个答案:

答案 0 :(得分:0)

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

由于在上一行中您已传递了一个参数,并且在控制器文件中方法名称没有任何参数,因此您的方法应类似于

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 ]);
}

答案 1 :(得分:0)

由于您正在使用模式,因此我建议您使用ajax。重定向回肯定会刷新页面。使用ajax,您可以在JS中获得响应并正确处理它。谢谢,祝你好运