jeudi 8 décembre 2016

Outputting single json object from array

In laravel I am trying to pass json data into my profile.blade.php view. I have the json query in my apicontroller.php which pulls data from my profile db table and then passes the data into the profile.blade.php using the profilecontroller.js.

I can see the data as an array in profile.blade.php using @ I get the output

[{"id":1,"username":"test","email":"test@gmail.com","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"}]

but if i try to get a single object e.g it doesn't output anything

How can i pull just the username or another object out of my array?

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

@  



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire