я все еще новичок и пытаюсь сохранить данные из файла REAXML.
поставщик для анализа REAXML из https://github.com/i4ucode/reaxml
Маршрут:
Route::get('/admin/synctest', 'Admin\\AdminController@synctest');
Свойство модели
class Property extends Model
{
protected $table = 'properties';
protected $primaryKey = 'id';
protected $fillable = ['refID', 'propkind_id', 'other column'];
public function Kind()
{
return Propkind::findOrfail($this->propkind_id)->name;
}
//other public function
}
Модель Propkind
class Propkind extends Model
{
protected $table = 'propkinds';
protected $primaryKey = 'id';
protected $fillable = ['id', 'name', 'slug'];
public function Property(){
return $this->hasMany('App\Property');
}
//other public function
}
Контроллер
public function synctest()
{
// get new class
$processor = new \REA\XmlProcessor();
$directories = Storage::disk('reaxml')->files();
foreach ($directories as $zipFile) {
//get XML file
$files = file_get_contents(url('feed/' . $zipFile));
//process the xml
$properties = $processor->parseXmlString($files);
//loop
foreach ($properties as $property) {
Property::updateOrCreate(
['refID' => $property->getRefID()],
[
//other code
'propkind_id' => Propkind::where('name', $property->getCategoryNaskleng())->first()->id, ===> ErrorException (E_NOTICE) Trying to get property of non-object
]
);
}
}
}
этот кусокcode Propkind::where('name', $property->getCategoryNaskleng())->first()->id)
==> показывать данные, но trow
ErrorException Пытаться получить свойство не-объекта.
какое-то просветление, мудрость, очень ценю.