コード例 #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     User::truncate();
     Post::truncate();
     Comment::truncate();
     Tag::truncate();
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
     $this->call(UserTableSeeder::class);
     $this->call(PostTableSeeder::class);
     $this->call(CommentTableSeeder::class);
     $this->call(TagTableSeeder::class);
     Model::reguard();
 }
コード例 #2
0
 public function latest()
 {
     return Post::orderBy('posted_on', 'desc');
 }
コード例 #3
0
 /**
  * @return \Illuminate\View\View
  */
 public function getVotee()
 {
     $model = Post::firstOrFail();
     return view('components/votee', compact('model'));
 }
コード例 #4
0
ファイル: api.php プロジェクト: perekljuchatel/blog
$app->register(new DoctrineOrmServiceProvider(), require_once 'app/config/db.orm.php');
$app->get('/posts', function () use($app) {
    $em = $app['orm.em'];
    $results = $em->getRepository('App\\Entities\\Post')->findAll();
    $hydrator = new CollectionExtractor(new DoctrineHydrator($em));
    return $app->json($hydrator->extract($results));
});
$app->get('/posts/{id}', function ($id) use($app) {
    $em = $app['orm.em'];
    $post = $em->getRepository('App\\Entities\\Post')->find($id);
    $hydrator = new DoctrineHydrator($em);
    return $app->json($hydrator->extract($post));
});
$app->post('/posts', function (Request $request) use($app) {
    $em = $app['orm.em'];
    $post = new Post();
    $post->setTitle($request->get('title'));
    $post->setContent($request->get('content'));
    $em->persist($post);
    $em->flush();
    return $app->json($hydrator->extract($post));
});
$app->put('/posts/{id}', function ($id, Request $request) use($app) {
    $em = $app['orm.em'];
    $post = $em->getRepository('App\\Entities\\Post')->find($id);
    $post->setTitle($request->get('title'));
    $post->setContent($request->get('content'));
    $em->persist($post);
    $em->flush();
    return $app->json($hydrator->extract($post));
});