php - Laravel 5.3 : hidden fields are returned in JSON response -


first of i've searched web answer , not find quite astonished me. maybe did not search right terms, please excuse me in advance if case.

so defined in model fields hidden :

protected $hidden = [     'hasexpired', 'hasbeentreated', 'reporterid' ]; 

and how output results :

return response()->json([          'latestreports' => $latestreports        ]); 

and $latestreports variable defined somewhere else :

$query = db::table('reports')             ->where('catid', 0) ;  $latestreports = $query->where('hasexpired', 0)             ->orderby('created_at', 'desc')             ->get(); 

how on earth possible these fields still appear in response on client server, , above should correct prevent them appearing. in other word how can make hidden array enforced ?

please note: other models (e.g. users) hidden array enforced, hidden fields not appear in response.

any appreciated.

the reason hidden fields shown fetch data database table directly using db::table() instead of using model. $hidden array used when serialising eloquent models json , you're bypassing eloquent layer way query has no way of knowing columns should hidden.

replace

$query = db::table('reports')->where('catid', 0); 

with

$query = report::where('catid', 0); 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -