please help i'm currently working on a real estate project and I have the following table as many to many relationship on Laravel 4.1
table categories
table services
table category_service
when I tested on PHPMyAdmin with the following query
SELECT C.category_name
FROM Categories AS C
LEFT JOIN category_service AS CS ON CS.category_id = C.id
LEFT JOIN Services S ON S.id = CS.service_id
WHERE S.id =1
the result is OK when I changed S.id to 2, but on Laravel the result was remain unchanged whether I changed its id = 2. Here is my Category class
class Category extends Eloquent {
protected $fillable = ['category_name'];
public $timestamps = false;
public function services() {
return $this->belongsToMany('Service','category_service');
}
}
and my Service class
class Service extends Eloquent {
protected $fillable = ['service_types'];
public $timestamps = false;
public function categories() {
return $this->belongsToMany('Category','category_service');
}
}
and the ServicesController
class ServicesController extends BaseController {
public function getService($c) {
//using raw query return the result unchanged
$cat = DB::raw('
SELECT C.category_name
FROM Categories AS C
LEFT JOIN category_service AS CS ON CS.category_id = C.id
LEFT JOIN Services S ON S.id = CS.service_id
WHERE S.id ='.$c
);
//using eloquent return the result unchanged
$cat = Service::with('categories')->find($c);
return View::make('members.cat')->with('cat',$cat);
}
}
Expected result should be like this photo with S.id=1
Expected result should be like this photo with S.id=1
so what I did wrong with Laravel? I show the result the same S.id=1 although I gave S.id=0 that didn't exist in database.