Guest User

Untitled

a guest
Jan 16th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. public function up()
  2. {
  3. Schema::create('contracts', function (Blueprint $table) {
  4. $table->increments('id');
  5. $table->string('java', 191)->nullable();
  6. $table->unsignedInteger('method_payment');
  7. $table->integer('kpi_dni')->nullable();
  8. $table->integer('kpi_ruc')->nullable();
  9. $table->integer('kpi_pos')->nullable();
  10. $table->integer('kpi_out')->nullable();
  11.  
  12. public function up()
  13. {
  14. Schema::create('clients', function (Blueprint $table) {
  15. $table->increments('id');
  16. $table->string('name');
  17. $table->unsignedInteger('document_user')->default(1);
  18. $table->string('document')->unique();
  19. $table->string('phone')->nullable();
  20. $table->string('address')->nullable();
  21. $table->string('email')->nullable();
  22. $table->timestamps();
  23.  
  24. $table->foreign('document_user')
  25. ->references('id')->on('document_users')
  26. ->onUpdate('cascade')
  27. ->onDelete('cascade');
  28. });
  29. }
  30.  
  31. public function up()
  32. {
  33. Schema::create('contract_client', function (Blueprint $table) {
  34. $table->increments('id');
  35. $table->integer('client_id')->unsigned();
  36. $table->integer('contract_id')->unsigned();
  37. $table->timestamps();
  38. });
  39. }
  40.  
  41. class Contract extends Model
  42.  
  43. public function clients()
  44. {
  45. return $this
  46. ->belongsToMany('AppClient')
  47. ->withTimestamps();
  48. }
  49.  
  50. class Client extends Model{
  51. public function contracts()
  52. {
  53. return $this
  54. ->belongsToMany('AppContract')
  55. ->withTimestamps();
  56. }
  57.  
  58. class ContractClient extends Model{
  59. protected $table='contract_client';
  60.  
  61. protected $fillable = [
  62. 'contract_id', 'client_id'
  63. ];
  64. public function contract(){
  65. return $this->belongsToMany('AppContract', 'id', 'contract_id');
  66. }
  67. public function client(){
  68. return $this->belongsToMany('AppClient', 'id', 'client_id');
  69. }
  70.  
  71. @foreach ($contracts as $contract)
  72. <tr>
  73. <td>{{$contract->clients()->get()}}</td>
Add Comment
Please, Sign In to add comment