2 回答
TA贡献1934条经验 获得超2个赞
也许你可以这样做:在app/Http/Controllers/Controller.php,添加方法response();
protected function view($viewPath, $content, $status = 200, array $headers = [])
{
if(request()->ajax()) {
return response()->json($content, $status, $headers);
}
return view($viewPath, $content);
}
然后你的控制器方法可以像这样使用:
public function create()
{
// logic
return $this->view('view_path', $data);
}
TA贡献2011条经验 获得超2个赞
我改变了你的功能
protected function ajaxView(string $viewPath, array $content = [], int $status = 200, array $headers = [])
{
$view = view($viewPath, $content);
if(request()->ajax()) {
dd($view->getData());
return response()->json([
'id' => $this->view->getData()['page'],
'title' => $this->view->getData()['title'],
'content' => $this->view->renderSections()['content'],
'replacepage' => null,
], $status, $headers);
}
return $view;
}
但是,如果记录不为空,如果我将 dd() 放在我的外部,则 dd() 记录数组为空
- 2 回答
- 0 关注
- 103 浏览
添加回答
举报