Ignore this. I was able to solve this. RETURN was missing in the models.
prasanthbpillai said:
Unit Model:
namespace App\Models\Qualification;
use Illuminate\Database\Eloquent\Model;
class Unit extends Model {
// protected $table = "unit"; public function qualifications() { $this->belongsToMany('\App\Models\Qualification', 'qualification_unit_xref'); }
}
qualification model:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Qualification extends Model {
public $timestamps = false; protected $table = "qualification";
// get the related training package it belong public function trainingpackage() { $this->belongsTo('\App\Models\TrainingPackage', 'package_id'); }
// get the units part of the qualification public function units() { $this->belongsToMany('\App\Models\Qualification\Unit', 'qualification_unit_xref', 'qualification_id', 'unit_id'); }
// get the industries associated with the qualification public function industries() { $this->belongsToMany('\App\Models\Qualification\Industry', 'qualification_industry_xref'); }
// get the occupation associated with qualification public function occupations() { $this->belongsToMany('\App\Models\Qualification\Occupation', 'qualification_occupation_xref'); } }
Controller function:
public function all() {
$qualifications = Qualification::with('units', 'trainingpackage')->get();
}
On executing I'm getting the following stack trace.
[2015-04-14 01:23:38] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to a member function addEagerConstraints() on a non-object' in C:\xampp\htdocs\gqtool\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php:439 Stack trace: #0 C:\xampp\htdocs\gqtool\storage\framework\compiled.php(1721): Illuminate\Foundation\Bootstrap\HandleExceptions->fatalExceptionFromError(Array) #1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown() #2 {main}
Can I get any help in resolving this?
--pbp
You need to return the statements inside the model functions.
so, the function below public function qualifications() { $this->belongsToMany('\App\Models\Qualification', 'qualification_unit_xref'); }
should be
public function qualifications() { return $this->belongsToMany('\App\Models\Qualification', 'qualification_unit_xref'); }
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community