我有一个注释表和用户表,其关系为:user-
FatalErrorException in Comment.php line 22: Call to undefined function App\belongsTo()
我的其他模型没有任何问题与Has很多关系,然而,评论模型有一个问题,我尝试的每一件事(即使我使用Has很多只是为了看看它是否会有不同的错误)。
下面是注释模型。
use Illuminate\Database\Eloquent\Model;
class Comment extends Model {
protected $table = 'comments';
protected $fillable = [
'anime_id',
'user_id',
'user_comment'
];
public function postedOnAnime($query)
{
$query->where('anime_id', '=', $this.id);
}
public function user()
{
return $this.belongsTo('App\User', 'user_id', 'id');
}
public function anime()
{
return $this.belongsTo('App\Anime');
}
}
以下是用户表:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->integer('role');
$table->string('name')->unique();
$table->string('email')->unique();
$table->string('password', 60);
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
这是评论表
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCommentsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('comments', function(Blueprint $table)
{
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->integer('anime_id')->unsigned();
$table->text('user_comment');
$table->timestamps();
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
$table->foreign('anime_id')
->references('id')
->on('animes')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('comments');
}
}
最后,当我调用$comment时-
谢谢
我认为这是来自其他语言的常见错误,其中.
用于访问属性。在PHP中,应该是-
$this.belongsTo('...')
应重写为$this-
返回$this.belongsTo('App\User','User\u id','id');要退还这美元吗-
发生此错误是因为我用.代替了-
我用Spring5反应式编写了一个自定义异常 我把这个叫做服务: 但是当我到达这个页面时,会抛出一个异常,但它不是404,而是一个空指针异常和一个错误500页面,但有正确的消息? AddressNotFound永远不会抛出,只有Nullpointer异常,但会抛出我的自定义消息???你能帮帮我吗? 这是我的控制器: 谢谢
我真的需要温习一下我的异步等待和promise。我想要一些建议。 我正在对firebase firestore进行异步函数调用。函数应根据单个输入参数返回字符串。 该功能适用于1-1用户聊天。该功能是创建聊天/查找现有聊天,并返回其ID。 现在,我得到的作为返回值的和不知道为什么。除了返回之外,该函数还能正常工作。 我有两个功能。一个是React类组件生命周期方法,另一个是我的firebase异步
问题内容: 我正在使用Linux,并且具有以下文件: 该函数在中声明和定义。我需要在中使用该函数,因此我将该函数声明为 在。 但是,在编译过程中,我得到了错误 怎么了? 谢谢。 预计到达时间:多亏了我收到的答案,我现在有了以下内容: 在fileA.h中,我有 在fileA.c中,我有 在fileB.h中,我有 在fileB.cpp中,我有 但是,我现在有错误 问题答案: 如果您确实是使用C而不是C
我有一个异步函数,它将一些数据插入数据库(使用Mariadb)。由于重复的唯一键,此插入可能会失败,因此它会抛出错误(实际上确实如此),但当我尝试再次抛出它以通过Promise捕获它时,它不起作用;它似乎总是以成功的案例结束,即使它抛出了错误。 我尝试改变then/catch顺序,我使用了< code > reject(err);而不是< code >抛出err但是这些都不起作用。 这是POST声
我的函数出现此错误。我正在尝试在按用户id提交报告之间添加5分钟计时器。但由于某些原因,我出现此错误。 这是我的控制器
在index.js,我有: 我从以下地方复制粘贴了代码:https://firebase.google.com/docs/functions/get-started 不知何故,当我使用 我得到: 错误:分析函数触发器时出错。ReferenceError:未在对象上定义函数。(/home/[USERNAME HERE]/functions/index.js:1:87)在模块中_在对象处编译(modu