0
無論我嘗試什麼,我都會收到同樣的錯誤;Laravel未定義的屬性錯誤
Undefined property: Illuminate\Database\Eloquent\Collection::$description
這是我的代碼在我的控制器;
$gorDistinct = PostcodeExtract::fromTable($tableName)
->distinct()
->select('gor')
->get();
foreach($gorDistinct as $key => $value)
{
print $value->gor;
$descGorLookup = GorLookup::select('description')
->where('oldcode', '=', $value->gor)
->get();
print $descGorLookup->description;
print "<br>";
exit;
}
這是我目前使用的GorLookup Model;
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class GorLookup extends Model {
protected $connection = 'postcodes';
protected $table = 'pc_gor_030315';
protected $fillable = array('description', 'oldcode');
}
我知道這並沒有充分利用Laravel的關係特性。現在我只需要讓這部分工作!
它返回數組,而不是讓你應該先用()來呼應說明 –