コード例 #1
0
 /**
  * Remove the specified resource from storage.
  *
  * @param ResourceRequest $request
  * @param  int            $id
  * @return \Illuminate\Contracts\Http\Response
  */
 public function destroy(ResourceRequest $request, $id)
 {
     $resource = $this->model->findOrFail($id);
     if (!$resource->delete()) {
         return $this->respond->internalError('Failed to delete !');
     }
     return $this->respond->success('Deleted');
 }
コード例 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param ResourceRequest $request
  * @return \Illuminate\Contracts\Http\Response
  */
 public function store(ResourceRequest $request)
 {
     // Merging author_id. In real project
     // we should use $request->user()->id instead.
     $data = array_merge($request->all(), ['author_id' => 1]);
     if (!($resource = Resource::create($data))) {
         return $this->respond->internalError('Failed to create !');
     }
     // respond created item with 201 status code
     return $this->respond->setStatusCode(201)->withItem($resource, new ResourceTransformer());
     // respond with simple message
     return $this->respond->created('Created');
 }
コード例 #3
0
ファイル: DatabaseSeeder.php プロジェクト: Kristories/fractal
 /**
  * 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");
 }
コード例 #4
0
 /** @before */
 public function stub()
 {
     $faker = \Faker\Factory::create();
     $this->author = \Appkr\Fractal\Example\Author::create(['name' => 'foo', 'email' => $faker->safeEmail]);
     $this->resource = \Appkr\Fractal\Example\Resource::create(['title' => $faker->sentence(), 'author_id' => $this->author->id, 'description' => $faker->randomElement([$faker->paragraph(), null]), 'deprecated' => $faker->randomElement([0, 1])])->toArray();
 }