public function run() { $faker = Faker\Factory::create(); $users = User::lists('id')->all(); foreach (range(1, 100) as $index) { $url = Url::create(['user_id' => $faker->boolean() ? $faker->randomElement($users) : null, 'destination' => $faker->url, 'password' => $faker->boolean() ? 'secret' : null]); UrlSlug::create(['url_id' => $url->id, 'slug' => $url]); } }
/** * 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(); }); }
/** * Handle the creation of a new URL * * @param StoreNewUrlCommand $command * @return void */ public function handle(StoreNewUrlCommand $command) { $url = Url::create(['user_id' => $this->auth->user() ? $this->auth->user()->id : null, 'destination' => $command->destination, 'password' => $command->password]); UrlSlug::create(['url_id' => $url->id, 'slug' => $url]); return $url; }