/**
  * Handle the command.
  *
  * @param  StoreNewSnippetCommand  $command
  * @return void
  */
 public function handle(StoreNewSnippetCommand $command)
 {
     if (empty($command->title)) {
         $command->title = str_limit($command->body, 10);
     }
     $snippet = Snippet::create(['user_id' => $command->user_id, 'title' => $command->title, 'body' => $command->body, 'mode' => $command->mode, 'password' => $command->password]);
     SnippetSlug::create(['snippet_id' => $snippet->id, 'slug' => $snippet]);
     return $snippet;
 }
Ejemplo n.º 2
0
 public function run()
 {
     $faker = Faker\Factory::create();
     $users = \DarkShare\Users\User::lists('id')->all();
     foreach (range(1, 100) as $index) {
         $snippet = Snippet::create(['user_id' => $faker->boolean() ? $faker->randomElement($users) : null, 'title' => $faker->sentence(), 'body' => $faker->paragraph(), 'mode' => 'markdown', 'password' => $faker->boolean() ? 'secret' : null]);
         SnippetSlug::create(['snippet_id' => $snippet->id, 'slug' => $snippet]);
     }
 }
Ejemplo n.º 3
0
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->bind('snippets', function ($value) {
         return SnippetSlug::where(\DB::raw('BINARY slug'), $value)->firstOrFail()->snippet;
     });
     $router->bind('files', function ($value) {
         return FileSlug::where(\DB::raw('BINARY slug'), $value)->firstOrFail()->file;
     });
     $router->bind('urls', function ($value) {
         return UrlSlug::where(\DB::raw('BINARY slug'), $value)->firstOrFail()->url;
     });
     $router->bind('username', function ($value) {
         return User::where('username', $value)->firstOrFail();
     });
 }