soprun
@soprun
Software Architecture

Как реализовать сложный запрос в laravel?

Подскажите как мне реализовать вывод страниц по приоритету.
Есть таблицы.
Schema::create('pages', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('category')->unsigned();
    $table->integer('status')->unsigned();
    $table->integer('priority')->unsigned();
    $table->timestamps();
});
Schema::create('pages_status', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('priority')->unsigned();
    $table->string('name', 60);
});
Schema::create('pages_priority', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('priority')->unsigned();
    $table->string('name', 60);
});
Schema::create('pages_category', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('priority')->unsigned();
    $table->string('name', 60);
});
Schema::table('pages', function(Blueprint $table) {
	$table->foreign('status')->references('id')->on('pages_status')
		->onDelete('restrict')
		->onUpdate('restrict');

	$table->foreign('priority')->references('id')->on('pages_priority')
		->onDelete('restrict')
		->onUpdate('restrict');
	
	$table->foreign('category')->references('id')->on('pages_category')
		->onDelete('restrict')
		->onUpdate('restrict');
});

Правило сортировки:
  1. По pages.pages_status учитывая значения приоритета pages_status.priority
  2. По pages.priority учитывая значения приоритета pages_priority.priority
  3. По pages.category учитывая значения приоритета pages_category.priority
  4. И все это по дате последнего изменения

В итоге первыми должны быть строчки имеющие наибольший приоритет и недавнее изменения.
  • Вопрос задан
  • 2455 просмотров
Пригласить эксперта
Ответы на вопрос 1
zvermafia
@zvermafia
WebDev
Чет не совсем понятно, можно по подробнее?
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы