V
V
Vladislav Soprun2015-02-08 18:48:59
MySQL
Vladislav Soprun, 2015-02-08 18:48:59

How to implement complex query in laravel?

Tell me how I can implement the output of pages by priority.
There are tables.

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');
});

Sorting rule:
  1. By pages.pages_status considering pages_status.priority priority values
  2. By pages.priority considering pages_priority.priority priority values
  3. By pages.category given priority values ​​pages_category.priority
  4. And all this by last modified date

As a result, the lines with the highest priority and recent changes should be the first.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mokhirjon Naimov, 2015-04-01
@zvermafia

Chet is not entirely clear, can you elaborate?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question