0

User.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
     protected $table = 'user';
     protected $primaryKey = 'id';
     public $timestamps = false;
     public function comments(){ 
         return $this->hasOne('App\Models\Comment', 'uid', 'uid');
     }
}

Comment.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
     protected $table = 'comment';
     protected $primaryKey = 'id';
     public $timestamps = false;
     public function comments(){ 
         return $this->hasMany('App\Models\User', 'uid', 'uid');
     }
}

我想在Test控制器中使用User模型中comments方法的数据 应该怎么使用呢?

use App\Models\User;
class TestController extends Controller{
     public function test(){

  }
}
添加评论
0 条评论
发布您的评论
  • 你的答案

发布您的答案