/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('ArticleDestinationMapping')->delete();
     if (($handle = fopen(dirname(__FILE__) . '/csv/ArticleDestinationMapping.csv', 'r')) !== FALSE) {
         $fields = fgetcsv($handle);
         while (($line = fgetcsv($handle, 1000, ',')) !== FALSE) {
             ArticleDestination::create($this->zipArray($fields, $line));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @param Request $request
  * @return Article
  */
 public function doPost(Request $request)
 {
     // TODO: Implement doPost() method.
     /** @var \App\Models\ContentBase $newContent */
     $newContent = ContentBase::create(['content_type' => 0]);
     $newArticle = $newContent->article()->create($request->only($this->articleFields));
     if ($request->input('cover_id') != 0) {
         $newArticle['cover_id'] = $request->input('cover_id');
         $newArticle->save();
     }
     // get all checked-in destinations
     /** @var array $dest */
     $dest = array_map(function ($item) {
         $rs = Destination::where('des_name', $item->des_name)->first();
         return $rs;
     }, (array) json_decode($request->input('destinations')));
     foreach ($dest as $d) {
         /** @var Destination $d */
         $m = new ArticleDestination();
         $m->article_id = $newArticle->article_id;
         $m->des_id = $d->des_id;
         $m->save();
     }
     // get all tagged tags
     $tags = array_map(function ($item) {
         return Tag::where('tag_name', $item->tag_name)->first();
     }, (array) json_decode($request->input('tagnames')));
     /** @var Tag $t */
     foreach ($tags as $t) {
         $m = new ArticleTag();
         $m->article_id = $newArticle->article_id;
         $m->tag_id = $t->tag_id;
         $m->save();
     }
     return $newArticle;
 }