fortune-eloquent.php 772 B

12345678910111213141516171819202122232425262728
  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. $rows = Fortune::all();
  13. $insert = new Fortune();
  14. $insert->id = 0;
  15. $insert->message = "Additional fortune added at request time.";
  16. $rows->add($insert);
  17. $rows = $rows->sortBy("message");
  18. ?>
  19. <!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>
  20. <?php foreach ( $rows as $fortune ) : ?>
  21. <tr><td><?= $fortune->id ?></td><td><?= htmlspecialchars($fortune->message, ENT_QUOTES, 'UTF-8') ?></td></tr>
  22. <?php endforeach ?></table></body></html>