I have set up a model User
and I created a controller to get some values:
<?php
namespace App\Http\Controllers;
use Dingo\Api\Routing\Helpers;
use Illuminate\Routing\Controller;
use App\Models\User;
class UserController extends Controller
{
use Helpers;
public function index()
{
$users = User::all();
return $users;
}
}
But when I run this, the json value is returned twice:
{
"users": [
{
"0": 1,
"1": "Firstname Lastname",
"2": "Accusantium commodi repellat quia eos. Cumque debitis qui deserunt aspernatur harum vitae aut.",
"3": "2016-12-04 21:56:59",
"4": "2016-12-04 21:56:59",
"extra_id": 1,
"name": "Firstname Lastname",
"profile": "Accusantium commodi repellat quia eos. Cumque debitis qui deserunt aspernatur harum vitae aut.",
"created_at": "2016-12-04 21:56:59",
"updated_at": "2016-12-04 21:56:59"
},
}
But, a strange thing: the response above is when I have an empty $visible[]
array in my User model. But when I set the $visible
to contain, for example, name
and profile
both values are only displayed once. What is the problem here? Why is it showing up twice?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2g94aoJ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire