У меня есть 3 модели, и я уже установил Relation.
Модель A:
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class ComponentA extends Model
{
protected $table = 'ComponentA';
protected $primaryKey = 'ComponentAId';
public function ComponentB() {
return $this->hasOne(
'App\Model\ComponentB', 'ComponentBId', 'ComponentBId'
);
}
Модель B:
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class ComponentB extends Model
{
protected $table = 'ComponentB';
protected $primaryKey = 'ComponentBId';
public function ComponentC() {
return $this->hasOne(
'App\Model\ComponentC', 'ComponentCId', 'ComponentCId'
)->withDefault();
}
}
Модель C:
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class ComponentC extends Model
{
protected $table = 'ComponentC';
protected $primaryKey = 'ComponentCId';
}
Теперь в контроллере я хочу вызвать C из A и отсортировать по столбцу C, я использую с () методом.
Контроллер:
$this->ComponentA->with(['ComponentB.ComponentC' => function($query) {
$query->orderby('ComponentCId','DESC');
}])->paginate();
Это верно, никаких ошибок, но результат не сортирует .
Пожалуйста, помогите мне, где я не прав?
Большое спасибо.