如何使用Laravel重定向发送数据

Ana*_*ent 21 php laravel blade laravel-4

我开发了一个API来在页面加载时显示弹出消息.

并非所有页面都使用弹出API.例如,如果用户转到该show($id)页面,则不需要弹出api来触发.但在某些特殊情况下,我需要弹出才能解雇.

这是我的代码,**这段代码只是为了说明我的观点,而不是实际的工作代码**

public function store(){
    validating the input

    saving them

    $id = get the id

    return Redirect::route('clients.show, $id')
}
Run Code Online (Sandbox Code Playgroud)

在show函数中我这样做:

public function show($id){
   $client =Client::find($id)
   return View::make('clients.profife')->with(array(
   'data' => $client
))
Run Code Online (Sandbox Code Playgroud)

我的问题

有没有办法让我可以使用Redirect :: routestore函数向show函数发送数据?然后在函数中,我检查是否有这个函数,我检查这个数据是否已经发送了什么然后我决定是否触发弹出api.showshow

}

del*_*ord 42

有存货()

return Redirect::route('clients.show, $id')->with( ['data' => $data] );
Run Code Online (Sandbox Code Playgroud)

show()阅读它

Session::get('data');
Run Code Online (Sandbox Code Playgroud)


voz*_*ldi 11

使用辅助函数的简单重定向.

因此,您无需在控制器模型中设置use Redirect也不需要use Session.

在Controller中处理某些内容后,插入:

return redirect()->route( 'clients.show' )->with( [ 'id' => $id ] );
Run Code Online (Sandbox Code Playgroud)

要检索'id'路由中的变量'clients.show'(如上所述),请使用:

// in PHP
$id = session()->get( 'id' );

// in Blade
{{ session()->get( 'id' ) }}
Run Code Online (Sandbox Code Playgroud)

  • 或者只是`session('id');` (laravel 5.7) (3认同)