0

I have a comments table and user table with the relationship: user->hasMany(‘comments’) and comment->belongsTo(‘user’). For some reason with which eludes me, I keep getting this

FatalErrorException in Comment.php line 22: Call to undefined function AppbelongsTo()

My other models have no issue whatsoever with the HasMany relations, however, the comments model has a problem with every single thing i try (even if i use HasMany just to see if it will have a different error).

Here is the Comment model.

use IlluminateDatabaseEloquentModel;

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('AppUser', 'user_id', 'id');
    }

    public function anime()
    {
        return $this.belongsTo('AppAnime');
    }

}

Here is the Users table:

<?php

use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;

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');
    }

}

Here is the Comments table

<?php

use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;

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');
    }

}

Finally, when I call $comment->user() it fails with the error. Does anyone know where this error comes from?

Thanks.