Before i start i would like to tell i am a begginer and i would like to learn more. I was reading a lot of tutorials but i never found and answer to my question.
Before we start i know what is rest and how it works.
What i dont know is how to create it with angularjs and laravel.
What i think about is, i have a database with mobile phones, and information about them (this is just an example in my mind)
Laravel Controller
<?php
class Phones_Controller extends Base_Controller {
public $restful = true;
public function get_index()
{
}
public function post_index()
{
}
public function get_show()
{
}
public function get_edit()
{
}
public function get_new()
{
}
public function put_update()
{
}
public function delete_destroy()
{
}
}
And here is the part where im clueless.
So the get/how function retunrs the phone beeing viewd by id in json
function
public function get_show($id)
{
$phones = Phone::find($id);
return Response::eloquent($phones);
}
So when i browse in the browser to http://mysite.com/phones/show/1 i see the json objects
Okay so this is what i mainly dont understand, when i am here `http://mysite.com/phones/show/1, how can i pass the resutls to a view?
I know how to use http request in angular, i dont get do i need to call the show function twice?
Example
$http({method: 'GET', url: '/phones/show/:id'}).
success(function(data, status, headers, config) {
$scope.phones = data;
}).
And create a nother laravel controller function to show the actually view the with the results?
If someone could point this out form me would be happy
Thank you
And create a nother laravel controller function to show the actually view the with the results?
Angular JS is your "view" - Laravel just sends the JSON results, which Angular grabs - and then Angular decides what to do with it.
If you want Laravel to be your "view" - then you dont want/need Angular - your duplicating your work/effort.
So in other words - Angular is your "front end" - it handles all the user experience, UI, requests etc. When Angular needs some data, like a user profile - it goes over to the "back end" (Laravel) and says "hey - can you give me user X profile". Laravel responds with JSON "no worries - here it is".
Angular then takes that JSON data - and displays it however you want.