fortune-eloquent.php 696 B

123456789101112131415161718192021222324
  1. <?php
  2. //
  3. // Database Test
  4. //
  5. require_once __DIR__ . '/boot-eloquent.php';
  6. class Fortune extends \Illuminate\Database\Eloquent\Model {
  7. protected $table = 'fortune';
  8. public $timestamps = false;
  9. protected $primaryKey = 'id';
  10. }
  11. // Define query and store result in array.
  12. $arr = Fortune::all()->pluck('message', 'id')->all();
  13. $arr[0] = 'Additional fortune added at request time.';
  14. asort($arr);
  15. ?>
  16. <!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>
  17. <?php foreach ( $arr as $id => $fortune ) : ?>
  18. <tr><td><?= $id ?></td><td><?= htmlspecialchars($fortune, ENT_QUOTES, 'UTF-8') ?></td></tr>
  19. <?php endforeach ?></table></body></html>