lundi 11 juin 2018

table not found one to many relationship laravel

my database

Schema::create('request_topics', function (Blueprint $table) {
        $table->increments('id');
        $table->string('title');
        $table->string('status')->nullable()->default('Pending');
        $table->integer('request_category_id')->unsigned()->index();
        $table->foreign('request_category_id')->references('id')->on('request_categories')
                    ->onDelete('cascade')
                    ->onUpdate('cascade');
        $table->integer('user_id')->unsigned()->index();
        $table->foreign('user_id')->references('id')->on('users')
                    ->onDelete('cascade')
                    ->onUpdate('cascade');
        $table->timestamps();
    });

and

Schema::create('request_categories', function (Blueprint $table) {
        $table->increments('id');
        $table->string('title')->unique();
        $table->string('slug')->unique();
        $table->string('description');
        $table->boolean('pin')->default(false);
        $table->timestamps();
    });

when i fetch like its working fine but when i fetch

$requesttopics = RequestTopic::whereHas('requestcategories', function ($query) use($slug){
            $query->where('slug', $slug);
        })->paginate('20');

getting error column not found

Column not found: 1054 Unknown column 'request_topics.requestcategories_id' in 'where clause' (SQL: select count(*) as aggregate from request_topics

something went wrong with my code or i am doing something wrong help me!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire