Guest User

Untitled

a guest
May 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. $factory->define(AppStatus::class, function (Faker $faker) {
  2. return [
  3. 'name' => $faker->word
  4. ];
  5. });
  6.  
  7.  
  8. $factory->define(AppStatusCategory::class, function (Faker $faker) {
  9. return [
  10. 'name' => $faker->word
  11. ];
  12. });
  13.  
  14. public function statuses() {
  15. return $this->belongsToMany( Status::class );
  16. }
  17.  
  18. public function statusCategories() {
  19. return $this->belongsToMany( StatusCategory::class );
  20. }
  21.  
  22. factory( Status::class, 30 )->create()->each( function ( $u ) {
  23. $u->statusCategories()->save( factory( StatusCategory::class )->make() );
  24. } );
  25.  
  26. <?php
  27.  
  28. namespace App;
  29. use IlluminateDatabaseEloquentModel;
  30.  
  31. class Status extends Model{
  32. protected $table='statuses';
  33. protected $fillable = [
  34. 'something you want to fill'
  35. ];
  36.  
  37. public function statusStatusCategories(){
  38. return $this->belongsToMany(StatusCategory::class);
  39. }
  40. }
  41.  
  42. <?php
  43.  
  44. namespace App;
  45. use IlluminateDatabaseEloquentModel;
  46.  
  47. class StatusCategory extends Model{
  48. protected $table='status_categories';
  49. protected $fillable = [
  50. 'something you want to fill'
  51. ];
  52.  
  53. public function statuses(){
  54. return $this->belongsToMany(Status::class);
  55. }
  56. }
  57.  
  58. namespace App;
  59. use IlluminateDatabaseEloquentRelationsPivot;
  60.  
  61. class StatusStatusCategory extends Pivot
  62. {
  63. protected $table='status_status_category';
  64. protected $fillable = [
  65. 'status_id','status_category_id'
  66. ];
  67.  
  68. public function status(){
  69. return $this->hasOne(Status::class, 'id', 'status_id');
  70. }
  71.  
  72. public function statuscategory(){
  73. return $this->hasOne(StatusCategory::class, 'id', 'statuscategory_id');
  74. }
  75. }
Add Comment
Please, Sign In to add comment