I defined an Eloquent model in Laravel AssessmentCategory with a with relation with another Eloquent model AssessmentQuestion:
<?php
namespace App\Http\Models;
use Illuminate\Database\Eloquent\Model;
class AssessmentCategory extends Model {
protected $table = 'assessment_categories';
protected $with = ['questions'];
public function scopeJsonColumns($query) {
return $query->selectRaw('assessment_categories.id, assessment_categories.title');
}
public function questions() {
return $this->hasMany(AssessmentQuestion::class, 'category_id');
}
}
the AssessmentCategory now always loads its relation (child) data, but I want to call the AssessmentCategory somewhere without loading the relation (child) data.
AssessmentCategory::jsonColumns()->get();