php - how to return json response in laravel -


this controller:

public function index(request $request)     {          $items = post::latest()->paginate(5);         $cmnt=comment::all();          return response()->json(array('posts'=>$items,'comment'=>$cmnt));     } 

**this ajax request **

function getpagedata() {       $.ajax({         datatype: 'json',         url: "{{route('post_status.index')}}",         data: {page:1}       }).done(function(data){          managerow(data.data);       });     } function managerow(data) {           console.log(data.comment); } 

why getting error ?? me out of plzz

laravel returns json default if doesn't return view, in case index() should return:

return ['posts' => $items,'comment' => $cmnt]; 

also don't think correct

{{route('post_status.index')}} 

probably should be

{{ url('post_status/index') }} 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -