Answer the question
In order to leave comments, you need to log in
Passing data laravel->angular?
Guys, sorry ... blunted.
return [
'sources' => Source::where('user_id', $request->user()->id)->get()->toJson(),
];
Order.get()
.success(function(data) {
console.log(data);
$scope.sources = data.sources;
console.log($scope.sources);
});
return [
'sources' => Source::where('user_id', $request->user()->id)->get()->toJson(),
'types' => [{'id'=>1,'type='нал'},{'id'=>'2','type'=>'карта']
];
Order.get()
.success(function(data) {
console.log(data);
$scope.sources = data.sources;
$scope.types = data.types;
console.log($scope.sources);
});
Answer the question
In order to leave comments, you need to log in
You will have a line in your sources, it is clear that there will be problems with ng-repeat.
In types, you also have heresy.
No need to pull toJSON or form it manually. just give an object and an array
return [
'sources' => Source::where('user_id', $request->user()->id)->first(),
'types' => [
['id'=>1, 'type' => 'нал'],
['id'=> 2, 'type' => 'карта']
]
];
apparently it turns out a string, not an array of objects, because the angular swears
There, in the documentation, it seems to be written that when returning without a view, json is given, that is, you don’t need to change it already. The guys thought this moment. Look in the Responses section just in case https://laravel.com/docs/5.2/responses#json-responses
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question