daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function showMessages()
  2. {
  3.     $participant_id = "+5555555";
  4.  
  5.     //$activeParticipant = Participant::where('participant_id', $participant_id);
  6.  
  7.     $activeParticipant = Participant::find($participant_id);
  8.     $messages = $activeParticipant->messages;
  9.  
  10.     dd($messages);
  11.     //$messages = Participant::find($participant_id)->messages;
  12. }
  13.    
  14. class CreateParticipantsTable extends Migration
  15. {
  16.  
  17. protected $primaryKey = 'participant_id';
  18. protected $incrementing = false;
  19.  
  20. public function up()
  21. {
  22.     Schema::create('participants', function (Blueprint $table) {
  23.         $table->string('participant_id')->unique()->primary();
  24.         $table->date('appointment_date')->nullable();
  25.         $table->boolean('subscribed');
  26.         $table->timestamps();
  27.     });
  28. }
  29.    
  30. <?php
  31. namespace App;
  32. use IlluminateDatabaseEloquentModel;
  33. class Participant extends Model
  34. {
  35. protected $table = 'participants';
  36.  
  37. protected $fillable = ['participant_id', 'appointment_date', 'subscribed'];
  38.  
  39. public function messages()
  40. {
  41.     return $this->hasMany(Message::class);
  42. //      return $this->hasMany('AppMessage', 'message_id', 'participant_id');
  43. }
  44. public function notifications()
  45. {
  46.     return $this->hasMany(Notification::class);
  47. }
  48. }
  49.    
  50. class CreateMessagesTable extends Migration
  51. {
  52. /**
  53.  * Run the migrations.
  54.  *
  55.  * @return void
  56.  */
  57. public function up()
  58. {
  59.     Schema::create('messages', function (Blueprint $table) {
  60.         $table->increments('id');
  61.         $table->integer('message_id')->unsigned();
  62.         $table->string('phoneNumber')->nullable();
  63.         $table->string('message_content')->nullable();
  64.         $table->string('mediaSID')->index()->nullable();
  65.         $table->string('messageSID')->index()->nullable();
  66.         $table->string('mediaURL')->index()->nullable();
  67.         $table->binary('media')->nullable();
  68.         $table->string('filename')->index()->nullable();
  69.         $table->string('MIMEType')->nullable();
  70.         $table->timestamps();
  71.         $table->foreign('message_id')->references('participant_id')->on('participants')->onDelete('cascade');
  72.     });
  73. }
  74.    
  75. <?php
  76. namespace App;
  77. use IlluminateDatabaseEloquentModel;
  78. class Message extends Model
  79. {
  80. protected $table = 'messages';
  81. protected $hidden = 'media';
  82. protected $fillable = ['message_id', 'phoneNumber', 'message_content', 'mediaSID', 'messageSID', 'mediaURL', 'media', 'filename', 'MIMEType'];
  83.  
  84. public function participant()
  85. {
  86.     return $this->belongsTo(Participant::class);
  87. }
  88. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top