hsntngr
1 year ago

How can I create query about relations and non relations tables ?

Posted 1 year ago by hsntngr

Well, it's hard to complain at the title, sorry for such a ridiculous title..

I have many tables named suspended_users, drafts, post_translations, products, reviews and specs

When I get the suspended user also I want to get related product about him. Suspect model have relation with Draft, Draft model have relation with PostTranslation.

I can easly acces the post_translations table, there is no problem with that. But I can't access the products, reviews or specs table from post_translations. How can I make it ?

Draft table for the suspicious reviews or product description (users are allowed to change those descriptions) If some users try to delete contents or try to spamming, I want to store them their posts as a draft.

So... Do you have any advice to make that ? I try with joins, relation load or with methods but didin't work yet..

Here are migrates..

Schema::create('suspended_users', function (Blueprint $table) {
            $table->increments('id');
            $table->integer("user_id")->unsigned();
            $table->integer("article_id")->unsigned();
            $table->timestamps();

            $table->foreign("user_id")->references("id")->on("users")->onDelete("cascade");
            $table->foreign("article_id")->references("id")->on("post_translations")->onDelete("cascade");
        });

Schema::create('drafts', function (Blueprint $table) {
            $table->increments('id');

            $table->integer("user_id")->unsigned()->nullable();
            $table->integer("article_id")->unsigned()->index();
            $table->longText("content");
            $table->timestamps();

            $table->foreign("article_id")->references("id")->on("post_translations")->onDelete("cascade");
            $table->foreign("user_id")->references("id")->on("users")->onDelete("cascade");
        });

Schema::create('post_translations', function (Blueprint $table) {
            $table->increments('id');

            $table->integer('post_id')->unsigned(); // means product or review id
            $table->integer("user_id")->unsigned();

            $table->string("post_type",20); // means table of post (like reviews)
            $table->string("post_status",20);
            $table->string('locale')->index();

            $table->longText('content')->nullable();
        });

Schema::create('products', function (Blueprint $table) {
            $table->increments('id');
            $table->string("title");
            $table->string("slug");
            $table->dateTime("release_date");
            $table->timestamps();
        });

Please sign in or create an account to participate in this conversation.