Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 1 year ago.
0

This should work:

Categories:find(1)->products()->get()

If not, maybe show us the models.

Last updated 1 year ago.
0

It doesn't work. Categories model:

<?php

class Categories extends Eloquent {

	protected $table = 'Categories';

	public function products() {
		return $this->belongsToMany('Products', 'product_category', 'product_id', 'category_id');
	}

}

?>

Products model:

<?php

class Products extends Eloquent {

	protected $table = 'Products';

	public function categories() {
		return $this->belongsToMany('Categories', 'product_category', 'product_id', 'category_id');
	}

}

?>
Last updated 1 year ago.
0

Thanks DrPrez for the solution.I'll remember it.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

SzkolaWEB szkolaweb Joined 26 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.