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": "Firstname Lastname",
"1": "Accusantium commodi repellat quia eos. Cumque debitis qui deserunt aspernatur harum vitae aut.",
"2": 1,
"3": "2016-12-04 21:56:59",
"4": "2016-12-04 21:56:59",
"name": "Firstname Lastname",
"profile": "Accusantium commodi repellat quia eos. Cumque debitis qui deserunt aspernatur harum vitae aut.",
"house_id": 1,
"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?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire