This is an example of how this can work. If your api endpoint names can also be urls, then you can do something like this:
// Controller
public function index() {
if ( Request::ajax() ) {
return ModelName::all(); // Returning from a model will automatically create JSON repsonse
// or
return Response::json($someArrayOfData); // You can pass any collection or array and JSON will be returned
}
// Normal request
return View::make('yourViewName', $data); // Request is a non-AJAX, so we will return a view, and pass the $data array to it
}
Hi!
Thank you very much.
But I have multiple questions based on your example:
Yeah and then I'd have the problem with versioning the API and Auth. Think OAuth would be the best for this since I want to make the API public some day.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community