use Kyslik\ColumnSortable\Sortable;
use EloquentFilter\Filterable;
class Building extends Model
{
use HasFactory;
use Sortable;
use Filterable;
public $sortable = ['id', 'code', 'description', 'created_at' , 'updated_at'];
public static function getTableName()
{
return (new self())->getTable();
}
//$product->getCampus
public function getCampus(){
return $this->belongsTo(Campus::class, 'campus', 'id' );
}
}
And when y sort by getCampus.id
Kyslik\ColumnSortable\Exceptions\ColumnSortableException
Relation 'getCampus' is not instance of HasOne or BelongsTo.
http://localhost/smart_clean_urv/public/buildings?direction=desc&sort=getCampus.id
If i not define the keys in belongsTo relationship:
use Kyslik\ColumnSortable\Sortable;
use EloquentFilter\Filterable;
class Building extends Model
{
use HasFactory;
use Sortable;
use Filterable;
public $sortable = ['id', 'code', 'description', 'created_at' , 'updated_at'];
public static function getTableName()
{
return (new self())->getTable();
}
//$product->getCampus
public function getCampus(){
return $this->belongsTo(Campus::class);
}
}
I have and a MYSQL error becouse my key is not campus_id , is only campus:
Illuminate\Database\QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'buildings.get_campus_id' in 'on clause' (SQL: select count(*) as aggregate from `buildings` left join `campuses` on `buildings`.`get_campus_id` = `campuses`.`id`)
http://localhost/smart_clean_urv/public/buildings?direction=desc&sort=getCampus.id
I have defined the relationship in the model:
And when y sort by getCampus.id
If i not define the keys in belongsTo relationship:
I have and a MYSQL error becouse my key is not campus_id , is only campus:
My Laravel version is 8.25.0
Thanks and sorry for my English!