“日志”中的每一行都包含密钥(dec_key),由用户在对系统进行身份验证时使用 表“键”包含键(dec_key)和用户ID(用户) 表“用户”包含用户ID(id)及其登录名(登录)
我正在尝试创建带有列的表单:
:log.id:keys.dec_key:keys.comment:users.login:
但是我的代码或数据库结构有问题。
这是我的数据库结构
handle = (e) => {
e.target.appendChild('<i className="fas fa-minus-circle"/>')
}
render() {
return (
<div className="container">
<button onClick={this.handle}>CLICK HERE</button>
</div>
)
}
我的代码
// LogsController.php
CREATE TABLE "log" (
"id" integer not null primary key autoincrement,
"dec_key" integer not null)
CREATE TABLE "keys" (
"id" integer not null primary key autoincrement,
"dec_key" integer not null,
"comment" varchar not null,
"user" integer not null, foreign key("dec_key") references "log"("dec_key") on delete cascade)
CREATE TABLE "users" (
"id" integer not null primary key autoincrement,
"login" varchar not null,
foreign key("id") references "keys"("user") on delete cascade)
// log.php
class LogsController extends Controller
{
public function index (Request $request) {
$req = Log::with('comment:dec_key,comment','keyusers:*');
}
}
// Key.php
class Log extends Model
{
protected $table = 'log';
public function comment () {
return $this->hasOne('App\Key', 'dec_key', 'dec_key');
}
public function keyusers()
{
return $this->hasManyThrough('App\Users', 'App\Key', 'user', 'id');
}
}
// Users.php
class Key extends Model
{
protected $table = 'keys';
public function userskeys()
{
return $this->belongsTo('App\Log','id','user');
}
public function users()
{
return $this->hasMany('App\Users','id','user');
}
}
keyusers方法返回一个空数组。 请帮助