laravelでは、jsonデータをprofile.blade.phpビューに渡そうとしています。私は私のapicontroller.phpのjsonクエリを持っています。私のプロファイルのdbテーブルからデータを取り出し、profilecontroller.jsを使ってprofile.blade.phpにデータを渡します。配列から単一のjsonオブジェクトを出力する
私は
[{"id":1,"username":"test","email":"[email protected]","password":"$2y$10$q2N/p3AD8FfUHxRVOF.aoecIKy8qcOBgvVurP4tZrcRdvZSS3JDOK","avatar":"default.jpg","remember_token":null,"created_at":"2016-12-07 22:29:57","updated_at":"2016-12-07 22:29:57"}]
出力を得るが、私は単一のオブジェクトなど{{ profiles.username }}
を取得しようとするならば、それは何も出力しません@{{ profiles }}
を使用してprofile.blade.phpの配列としてデータを見ることができます
ユーザー名や別のオブジェクトを配列から取り出すにはどうすればよいですか?
apiController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\UserDetail;
use App\Users;
use View;
use Auth;
class ApiController extends Controller
{
public function showAll()
{
return response()->json(
$details = Users::get()
);
}
}
profilecontroller.js
app.controller('profileController', function($scope, $http) {
$http.get('/api/hello')
.success(function(data, status, headers, config) {
$scope.profiles = data;
})
.error(function(error, status, headers, config) {
console.log(status);
console.log("Error occured");
});
profile.blade.php
@ {{profile}}
これを実行するために使用しているJavaScriptのフレームワークは何ですか?そして、使用しているビュー全体を投稿できますか? – Jerodev
オブジェクトは配列内にあります。 '{{profiles {0} .username}}' – Daan
ありがとうございました。これは角を使っていることを忘れています –