为什么查询出来的结果里面user字段下的数据不对?user下面应该是user表里面的内容 可是结果却是blog表里面的内容 这是为什么?弄了一天也不知道是怎么回事 大家能帮我看看吗?测试了一下并不是缓存的问题BlogController.php
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\Blog;
use App\Models\User;
class BlogController extends Controller
{
public function test (Request $request) {
$res = Blog::with('user')->get()->toArray();
dd($res);
}
}
Blog模型
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Blog extends Model
{
protected $table = 'blog';
protected $primaryKey = 'id';
public $timestamps = false;
protected $fillable = ['id', 'uid', 'content', 'href', 'create_at'];
public function user()
{
return $this->hasOne('App\Models\User','uid','uid');
}
}
User模型
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $table = 'blog';
protected $primaryKey = 'id';
public $timestamps = false;
protected $fillable = ['id', 'uid', 'email', 'password', 'tel', 'role', 'created_at'];
}
blog表
user表
慕田峪9158850