public function run()
 {
     $this->command->info('Deleting existing PortfolioPost table...');
     DB::table('portfolioposts')->truncate();
     $count = 20;
     $lang = array('fr', 'en');
     $faker = Faker\Factory::create('fr_FR');
     $this->command->info('Inserting ' . $count . ' sample Portfolio Posts...');
     for ($i = 0; $i < $count; $i++) {
         $title = e(substr($faker->sentence(8), 0, -1));
         $content = '<p>' . implode('</p><p>', $faker->paragraphs(5)) . '</p>';
         $post = PortfolioPost::create(array('title' => $title, 'slug' => Str::slug($title), 'content' => e($content), 'draft' => rand(0, 1), 'lang' => $lang[rand(0, 1)], 'image' => null, 'user_id' => 1, 'meta_title' => e($title), 'meta_keywords' => str_replace(' ', ', ', strtolower($title)), 'meta_description' => strip_tags($content)));
         $nb_occur = rand(1, 4);
         $range = range(1, 5);
         shuffle($range);
         for ($j = 0; $j < $nb_occur; $j++) {
             echo $post->tags()->attach($range[$j]);
         }
     }
     $this->command->info('Portfolio Posts inserted successfully!');
 }
Пример #2
0
 /**
  * Publish or UnPublish a post.
  *
  * @param  int  $id
  * @return Response
  */
 public function publish($id, $state)
 {
     // Get the page data
     if (is_null($post = PortfolioPost::find($id))) {
         // Redirect to Portfolio management page
         return Redirect::route('portfolio.admin')->with('error', Lang::get('modules/portfolio/messages.error.not_found'));
     }
     $post->draft = $state;
     // Was the page created?
     if ($post->save()) {
         // Redirect to the Portfolio management page
         return Redirect::route('portfolio.admin')->with('success', Lang::get('modules/portfolio/messages.success.publish'));
     }
     // Redirect to the Portfolio management page
     return Redirect::route('portfolio.admin')->with('error', Lang::get('modules/portfolio/messages.error.publish'));
 }