![]()
WARNING You're browsing the documentation for an upcoming version of Laravel DataTables. The documentation and features of this release are subject to change.
Ignore Model Getters
The ignoreGetters() API prevents Eloquent model getters and mutators from being applied when converting models to array for the DataTables response.
Basic Usage
use Yajra\DataTables\Facades\DataTables;use App\Models\User; Route::get('user-data', function() { return DataTables::eloquent(User::query()) ->ignoreGetters() ->toJson();});
Use Case
When you need to access the raw attribute values without any transformation:
use Yajra\DataTables\Facades\DataTables;use App\Models\User; Route::get('user-data', function() { // Model has an accessor that formats the name // class User extends Model { // public function getNameAttribute($value) { // return strtoupper($value); // } // } return DataTables::eloquent(User::query()) ->ignoreGetters() ->toJson();});
In this example, name will return the raw database value instead of the formatted uppercase value from the accessor.
With Relations
When eager loading relations, ignoreGetters also applies to related models:
use Yajra\DataTables\Facades\DataTables;use App\Models\User; Route::get('user-data', function() { return DataTables::eloquent( User::with(['posts', 'roles']) ) ->ignoreGetters() ->toJson();});
See Also
- Add Column - Adding custom columns
- Edit Column - Modifying existing columns