/** * Display a listing of the resource. * * @param null $id * @return \Illuminate\Contracts\Http\Response */ public function index($id = null) { // process v1.authors.things route if ('v1.authors.things' === \Route::currentRouteName()) { return $this->respond->setMeta($this->meta)->withPagination(Author::find($id)->things()->latest()->paginate(25), new ThingTransformer()); } // Respond with pagination return $this->respond->setMeta($this->meta)->withPagination($this->model->latest()->paginate(25), new ThingTransformer()); // Respond as a collection //return $this->respond->setMeta($this->meta)->withCollection( // $this->model->latest()->get(), // new ThingTransformer //); }
/** * Run the database seeds. * * @return void */ public function run() { Eloquent::unguard(); $faker = Faker::create(); // Seeding authors table Author::truncate(); foreach (range(1, 10) as $index) { Author::create(['name' => $faker->userName, 'email' => $faker->safeEmail]); } $this->command->line("<info>Seeded:</info> authors table"); // Seeding resources table Resource::truncate(); $authorIds = is_51() ? Author::lists('id')->toArray() : Author::lists('id'); foreach (range(1, 100) as $index) { Resource::create(['title' => $faker->sentence(), 'author_id' => $faker->randomElement($authorIds), 'description' => $faker->randomElement([$faker->paragraph(), null]), 'deprecated' => $faker->randomElement([0, 1])]); } $this->command->line("<info>Seeded:</info> resources table"); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Contracts\Http\Response */ public function show($id) { return $this->respond->setMeta($this->meta)->withItem($this->model->with('things')->findOrFail($id), new AuthorTransformer()); }
/** @before */ public function stub() { $faker = \Faker\Factory::create(); $this->author = \Appkr\Fractal\Example\Author::create(['name' => 'foo', 'email' => $faker->safeEmail]); $this->things = \Appkr\Fractal\Example\Thing::create(['title' => $faker->sentence(), 'author_id' => $this->author->id, 'description' => $faker->randomElement([$faker->paragraph(), null]), 'deprecated' => $faker->randomElement([0, 1])])->toArray(); }