ForeignKeyDefinition.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Illuminate\Database\Schema;
  3. use Illuminate\Support\Fluent;
  4. /**
  5. * @method ForeignKeyDefinition deferrable(bool $value = true) Set the foreign key as deferrable (PostgreSQL)
  6. * @method ForeignKeyDefinition initiallyImmediate(bool $value = true) Set the default time to check the constraint (PostgreSQL)
  7. * @method ForeignKeyDefinition on(string $table) Specify the referenced table
  8. * @method ForeignKeyDefinition onDelete(string $action) Add an ON DELETE action
  9. * @method ForeignKeyDefinition onUpdate(string $action) Add an ON UPDATE action
  10. * @method ForeignKeyDefinition references(string|array $columns) Specify the referenced column(s)
  11. */
  12. class ForeignKeyDefinition extends Fluent
  13. {
  14. /**
  15. * Indicate that updates should cascade.
  16. *
  17. * @return $this
  18. */
  19. public function cascadeOnUpdate()
  20. {
  21. return $this->onUpdate('cascade');
  22. }
  23. /**
  24. * Indicate that updates should be restricted.
  25. *
  26. * @return $this
  27. */
  28. public function restrictOnUpdate()
  29. {
  30. return $this->onUpdate('restrict');
  31. }
  32. /**
  33. * Indicate that updates should have "no action".
  34. *
  35. * @return $this
  36. */
  37. public function noActionOnUpdate()
  38. {
  39. return $this->onUpdate('no action');
  40. }
  41. /**
  42. * Indicate that deletes should cascade.
  43. *
  44. * @return $this
  45. */
  46. public function cascadeOnDelete()
  47. {
  48. return $this->onDelete('cascade');
  49. }
  50. /**
  51. * Indicate that deletes should be restricted.
  52. *
  53. * @return $this
  54. */
  55. public function restrictOnDelete()
  56. {
  57. return $this->onDelete('restrict');
  58. }
  59. /**
  60. * Indicate that deletes should set the foreign key value to null.
  61. *
  62. * @return $this
  63. */
  64. public function nullOnDelete()
  65. {
  66. return $this->onDelete('set null');
  67. }
  68. /**
  69. * Indicate that deletes should have "no action".
  70. *
  71. * @return $this
  72. */
  73. public function noActionOnDelete()
  74. {
  75. return $this->onDelete('no action');
  76. }
  77. }