I am totally new to angularjs and i am practicing.
I am a bit stuck with the following, i have a profile page what loads the users details, and i do not really know how to show it, problem is im stuck with the logic.
I created 2 routes for it
Route::get('/(:any)', array('as' => 'profile', 'uses' => 'user@profile'));
Route::get('/details/(:any)', array('as' => 'profile', 'uses' => 'user@details'));
So the url actually looks like this: http://mysite.com/username
So my logic works like this, this route
Route::get('/(:any)', array('as' => 'profile', 'uses' => 'user@profile'));
Returns the profile view
this route would fetch the users data in json
Route::get('/details/(:any)', array('as' => 'profile', 'uses' => 'user@details'));
and what i am stuck with is this
I load the view, http://mysite.com/username
i get the profile page,
Laravel view load
public function get_profile($username = '')
{
return View::make('user.profile');
}
Loading the json
public function get_details($username = '')
{
$users = User::where_username($username)->get();
return Response::eloquent($users);
}
angularjs controller
function profileCtrl($scope, $http) {
//here get the url first segment somehow
// and pass it to the get
// example
// urlSegment = username
$http('details/' + username ).success(function(data){
$scope.users = data;
console.debug(data);
});
}
So my question is, am i doing this okay, or im completly not on the right track. Could someone show me an exampe for this?
Thank you
EDIT
To be more specific, i am trying to create a restful api with angularjs and laravel but im a bit stuck with it. What i do not understand is the routing logic.
example.
mysite.com/username
, What type of route logic i need to build up to fetch the data?
Because i explained above, i created 2 routes for it, and i think thats not good.