Laravel 4 Laravel 4:为什么我不能在我的Laravel代码中使用别名
这是我的密码:Laravel 4 Laravel 4:为什么我不能在我的Laravel代码中使用别名,laravel-4,Laravel 4,这是我的密码: public function getReports() { $reports=DB::table('reports') ->select(array('*',DB::raw('reports.id','reports.departmentID','reports.officerID','reports.created_at','reports.report','reports.title','dep
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',
);
}
实际模型是什么样子的?本例中字段的名称是什么?用模型更新了问题。