Example #1
0
 public function saveCategory(Request $request)
 {
     $category = new \App\Category();
     $category->name = $request->input("name");
     $category->description = $request->input("description");
     $category->save();
     return Redirect::to('blog')->withInput()->with('success', 'Categoria creada exitosamente.');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = \Validator::make(\Input::all(), \App\Category::$rules);
     if ($validator->passes()) {
         $category = new \App\Category();
         $category->name = \Input::get('name');
         $category->save();
         flash('Category added.');
         return \Redirect::back();
     }
     return \Redirect::back()->withInput()->withErrors($validator);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     $content = "この文章はダミーです。あいうえおかきくけこ。この文章はダミーです。あいうえおかきくけこ。この文章はダミーです。あいうえおかきくけこ。この文章はダミーです。あいうえおかきくけこ。この文章はダミーです。あいうえおかきくけこ。この文章はダミーです。あいうえおかきくけこ。この文章はダミーです。あいうえおかきくけこ。";
     $commentdammy = "コメントダミー。コメントダミー。コメントダミー。";
     for ($i = 1; $i <= 10; $i++) {
         $post = new App\Post();
         $post->title = "{$i} 番目の投稿";
         $post->content = $content;
         $post->cat_id = 1;
         $post->save();
         $maxComments = mt_rand(3, 15);
         for ($j = 0; $j <= $maxComments; $j++) {
             $comment = new App\Comment();
             $comment->commenter = '名無しさん';
             $comment->comment = $commentdammy;
             $post->comments()->save($comment);
             $post->increment('comment_count');
         }
     }
     // Category
     $cat1 = new App\Category();
     $cat1->name = "ニュース";
     $cat1->save();
     $cat2 = new App\Category();
     $cat2->name = "食品";
     $cat2->save();
     $cat3 = new App\Category();
     $cat3->name = "電化製品";
     $cat3->save();
     $cat4 = new App\Category();
     $cat4->name = "テレビ";
     $cat4->save();
     $cat5 = new App\Category();
     $cat5->name = "文化";
     $cat5->save();
     $cat6 = new App\Category();
     $cat6->name = "映画";
     $cat6->save();
     $cat7 = new App\Category();
     $cat7->name = "スポーツ";
     $cat7->save();
     $cat8 = new App\Category();
     $cat8->name = "ゲーム";
     $cat8->save();
     $cat9 = new App\Category();
     $cat9->name = "社会";
     $cat9->save();
     $cat10 = new App\Category();
     $cat10->name = "教育";
     $cat10->save();
 }
 public function storeCategory()
 {
     $input = Input::all();
     $validate = Validator::make(Input::all(), ['name' => 'required']);
     if (!$validate->fails()) {
         $name = Input::get('name');
         $description = Input::get('description');
         $standard = Input::get('standard');
         $category = new \App\Category();
         $category->name = $name;
         $category->description = $description;
         $category->standard = $standard;
         $category->save();
         return redirect("admin/categories")->with('success', 'Category added successfully!');
     } else {
         return Redirect::back()->with('error', 'Error: Please fill name');
     }
 }