Laravel 5 如何 return 带有 response()->json() 的模板?
Laravel 5 how to return a template with response()->json()?
下面是我的数据库:
post:
id user_name content created_at
下面是我的 post 控制器:
public function new(Request $request){
$data = $request->all();
$post = new Post;
$post->user_name = $data['name'];
$post->message = $data['content'];
$post->save();
$id = $post->id;
$show = Post::find($id)->first();
// $html = view('wall.post')->with('post', $show);
return response()->json(['success' => $post->id,'message'=> 'Post Sent', 'html' => $html]);
}
和我的 /views/wall/post.blade.php :
<div class="ui post">
<div class="name">User : {{ $post->user_name }}</div>
<div class="content">{{ $post->content }}</div>
</div>
下面是我的问题:
how do i get the content from post.blade.php with user_name and
content return as below to $html in new() when i post name=kenny and content=testing:
<div class="ui post">
<div class="name">User : Kenny</div>
<div class="content">Testing</div>
</div>
我只是使用 jquery 将以上代码添加到我的页面?
谢谢
{对不起,如果我的英语语法不好}
您可以像这样渲染视图:
<?php
$html = view('wall/post')->render();
下面是我的数据库:
post:
id user_name content created_at
下面是我的 post 控制器:
public function new(Request $request){
$data = $request->all();
$post = new Post;
$post->user_name = $data['name'];
$post->message = $data['content'];
$post->save();
$id = $post->id;
$show = Post::find($id)->first();
// $html = view('wall.post')->with('post', $show);
return response()->json(['success' => $post->id,'message'=> 'Post Sent', 'html' => $html]);
}
和我的 /views/wall/post.blade.php :
<div class="ui post">
<div class="name">User : {{ $post->user_name }}</div>
<div class="content">{{ $post->content }}</div>
</div>
下面是我的问题:
how do i get the content from post.blade.php with user_name and content return as below to $html in new() when i post name=kenny and content=testing:
<div class="ui post">
<div class="name">User : Kenny</div>
<div class="content">Testing</div>
</div>
我只是使用 jquery 将以上代码添加到我的页面?
谢谢
{对不起,如果我的英语语法不好}
您可以像这样渲染视图:
<?php
$html = view('wall/post')->render();