I have a statement like this:
App\\User::with(\'client\')->find(2)->makeHidden(\'client.phone_no\');
I want to hide certain columns f
You can create a scope
in your model and apply it in builder
Define these functions in your model
protected function columns(){
return Schema::getColumnListing('clients');
}
public function scopeExclude($query, $value = array())
{
return $query->select( array_diff( $this->columns(), $value) );
}
Now use it in query builder
App\User::with(['client' => function($query){
$query->exclude(['phone_no']);
}])->find(2)