dimanche 28 juin 2015

Laravel 5 how to return a template with response()->json()?

Below is my database:

post:
id user_name content created_at

Below is my post controller:

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

and my /views/wall/post.blade.php :

<div class="ui post">
<div class="name">User : {{ $post->user_name }}</div>
<div class="content">{{ $post->content }}</div>
</div>

Below is my question:

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>

and i just use jquery to prepend above code to my page?

Thanks

{Sorry if i got bad grammar in my english}

Aucun commentaire:

Enregistrer un commentaire