Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. class Chat extends Model
  2. {
  3. protected $primaryKey = 'chat_id';
  4. protected $guarded = [];
  5.  
  6. public function comment()
  7. {
  8. return $this->hasOne(Comments::class, 'comment_id', 'comment_id');
  9. }
  10. }
  11.  
  12. class Comments extends Model
  13. {
  14. protected $primaryKey = 'comment_id';
  15. protected $guarded = [];
  16. }
  17.  
  18. public function up()
  19. {
  20. Schema::create('comments', function (Blueprint $table) {
  21. $table->increments('comment_id');
  22. $table->integer('user_id')->unsigned()->index('comments_user_id');
  23. $table->boolean('mark');
  24. $table->string('nick_name', 15)->nullable();
  25. $table->text('comment', 65535);
  26. });
  27. }
  28.  
  29. $comment = Comments::create([
  30. 'user_id' => 1,
  31. 'mark' => 50,
  32. 'comment' => 'Lorem ipsum dolor es at'
  33. ]); // $comment->comment_id = 1
  34.  
  35. $comment = $chat->comment()->create([
  36. 'user_id' => 1,
  37. 'mark' => 50,
  38. 'comment' => 'Lorem ipsum dolor es at',
  39. ]); // $comment->comment_id = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement