用户拥有许多用户TroughtPivotLaravel7.x
好的,我这里有个问题,本来应该是简单的,但没有想到这一点 我有一个用户表用户拥有许多用户TroughtPivotLaravel7.x,laravel,pivot-table,has-many-through,Laravel,Pivot Table,Has Many Through,好的,我这里有个问题,本来应该是简单的,但没有想到这一点 我有一个用户表 $table->increments('id'); $table->string('name'); $table->string('email')->unique()->nullable(); $table->string('telefono')->nullable();
$table->increments('id');
$table->string('name');
$table->string('email')->unique()->nullable();
$table->string('telefono')->nullable();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
每个用户都有一个静态角色
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('slug');
$table->timestamps();
});
比如说
用户Jhon具有家庭领导者的角色
和用户:
Schema::create('relation', function (Blueprint $table) {
$table->unsignedInteger('user_id');
$table->unsignedInteger('relation_id');
//FOREIGN KEY CONSTRAINTS
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('relation_id')->references('id')->on('users')->onDelete('cascade');
});
因此,User_id是关系的父对象,每个父对象都有在表中注册的拍卖属性
Schema::create('auction', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->text('description');
$table->unsignedInteger('user_id');
$table->timestamp('endate');
//FOREIGN KEY CONSTRAINTS
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
这个表上的用户id是父用户id
好吧,我的问题是,当一个孩子登录时,你可以得到一个列表上的所有拍卖。所以我做了一些关系
User Model
所以我想打电话给你
$auctions = $user->auctions()
->orderBy('created_at', 'desc')
->first();
$auctions = $user->auctions()
->orderBy('created_at', 'desc')
->first();