Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Chat extends Model
- {
- protected $primaryKey = 'chat_id';
- protected $guarded = [];
- public function comment()
- {
- return $this->hasOne(Comments::class, 'comment_id', 'comment_id');
- }
- }
- class Comments extends Model
- {
- protected $primaryKey = 'comment_id';
- protected $guarded = [];
- }
- public function up()
- {
- Schema::create('comments', function (Blueprint $table) {
- $table->increments('comment_id');
- $table->integer('user_id')->unsigned()->index('comments_user_id');
- $table->boolean('mark');
- $table->string('nick_name', 15)->nullable();
- $table->text('comment', 65535);
- });
- }
- $comment = Comments::create([
- 'user_id' => 1,
- 'mark' => 50,
- 'comment' => 'Lorem ipsum dolor es at'
- ]); // $comment->comment_id = 1
- $comment = $chat->comment()->create([
- 'user_id' => 1,
- 'mark' => 50,
- 'comment' => 'Lorem ipsum dolor es at',
- ]); // $comment->comment_id = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement