/** * Run the database seeds. * * @return void */ public function run() { DB::table('Article')->delete(); $csv = new CSV(); $articles = $csv->fromFile(dirname(__FILE__) . '/csv/Article.csv')->toArray(); foreach ($articles as $a) { $content = \App\Models\ContentBase::create(["content_type" => 0]); $content->article()->create($a); } }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('Photo')->truncate(); if (($handle = fopen(dirname(__FILE__) . '/csv/Photo.csv', 'r')) !== FALSE) { fgetcsv($handle); while (($line = fgetcsv($handle, 1000, ',')) !== FALSE) { $content = \App\Models\ContentBase::create(["content_type" => 1]); $content->photo()->create(array('username' => $line[0], 'des_id' => $line[1], 'photo_like' => $line[2], 'internal_url' => $line[3])); } } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @param Article $article * @return \Illuminate\Http\Response */ public function store(Request $request, Article $article) { $comment = new Comment(); $comment->comment_content = $request->get('comment_content'); $comment->username = Auth::user()->username; /** @var \App\Models\ContentBase $contentBase */ $contentBase = ContentBase::create(['content_type' => 2]); $comment->comment_id = $contentBase->content_id; $parent = $request->get('parent_comment'); if ($parent) { $comment->content_id = $parent; } else { $comment->content_id = $article->content->content_id; } $comment->save(); if ($request->ajax()) { return response()->json($comment); } return response(''); }
/** * @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; }