这是我的代码:
public function getReports()
{
$reports=DB::table('reports')
->select(array('*',DB::raw('reports.id','reports.departmentID','reports.officerID','reports.created_at','reports.report','reports.title','department.name','posts.name AS pname')))
->leftjoin('department','reports.departmentID','=','department.id')
->leftjoin('posts','reports.postID','=','posts.id')
->leftjoin('users','reports.officerID','=','users.id')
->leftjoin('events','events.id','=','reports.eventID')
->orderBy('reports.id','DESC')
->get();
$reportsArray=array();
foreach($reports as $row)
{
$reportsArray[]=array(
'id'=>$row->id,
'report'=>$row->report,
'title'=>$row->title,
'departmentName'=>$row->name,
'created_at'=>$row->created_at,
'post'=>$row->pname,
);
}
return View::make('reports.reports')
->with('reports',$reportsArray);
}
加载视图时出现以下错误:未定义属性:stdClass :: $ pname 这基本上是一个问题,因为我需要在许多实例中使用别名。当我尝试对任何列使用列别名时,错误基本相同。任何人都可以看到我的代码存在问题吗?
我的模特:
class Report extends Eloquent
{
protected $table = 'reports';
protected $fillable= array(
'title','reportDate',,'departmentID','date','eventID','officerID','postID',
);
}