Enabled/Improved links to relationships

This commit is contained in:
Deon George
2016-07-01 14:37:55 +10:00
parent b8be45b42c
commit ad10cb32ce
5 changed files with 57 additions and 23 deletions

View File

@@ -66,14 +66,14 @@ class Import extends Command
if ($this->option('tags'))
{
$tags = explode(',',$this->option('tags'));
$t = Tag::whereIn('tag',$tags)->get();
$t = Tag::whereIn('tag',$tags)->pluck('id');
}
// People
if ($this->option('people'))
{
$tags = explode(',',$this->option('people'));
$p = Person::whereIn('tag',$tags)->get();
$p = Person::whereIn('tag',$tags)->pluck('id');
}
$c = 0;
@@ -167,25 +167,9 @@ class Import extends Command
if ($po->wasRecentlyCreated)
$this->info(sprintf('Image [%s] stored in DB: %s',$file,$po->id));
// Record our tags
foreach ($t as $o)
if (! (new PhotoTag)->where('tag_id','=',$o->id)->where('photo_id','=',$po->id)->count())
{
$x = new PhotoTag;
$x->tag_id = $o->id;
$x->photo_id = $po->id;
$x->save();
}
// Record our people
foreach ($p as $o)
if (! (new PhotoPerson)->where('people_id','=',$o->id)->where('photo_id','=',$po->id)->count())
{
$x = new PhotoPerson;
$x->people_id = $o->id;
$x->photo_id = $po->id;
$x->save();
}
// Record our people and tags
$po->People()->sync($p->toArray());
$po->Tags()->sync($t->toArray());
}
$bar->finish();