Why don'y work relationships?

Posted 1 month ago by alex_storm

Hello, I created next simple relationships:

Categories

Schema::create('categories', function (Blueprint $table) {
            $table->Increments('category_id');
            $table->integer('status')->default(1);
            $table->timestamps();
        });

Languages

Schema::create('languages', function (Blueprint $table) {
            $table->bigIncrements('language_id');
            $table->string('code')->unique();
            $table->string('locale');
            $table->string('icon')->nullable();
            $table->integer('sort_order')->default(1);
            $table->integer('status')->default(1);
            $table->timestamps();
        });

And temp table for relationships

Schema::create('category_description', function (Blueprint $table) {
            $table->integer('category_id');
            $table->integer('language_id');
            $table->string('name');
            $table->string('description');
            $table->string('seo_title');
            $table->string('seo_description');
            $table->string('seo_keywords');
            $table->string('seo_h1');
        });

I use relationships many to many.

And I created in Category model next method

public function description()
    {
        return $this->belongsToMany('App\Models\Settings\Language','category_description','category_id','language_id');
    }

For language I created next method:

public function Categories()
    {
        return $this->belongsToMany('App\Models\Category','category_description','language_id','category_id');
    }

Then, I trying to get my description for all categories. I tried write - Category::all() (and I don't see relationships) I Tried to write $category->description and I got nothing (

How I can get my description for category(ies) ?

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

Reply to

Use Markdown with GitHub-flavored code blocks.