mysql - 调用模型 [App\Salarie] 上的未定义关系 [pointage]?

标签 mysql laravel database-migration

我想显示来自 ControllerSalarie 的 POINTAGE 和 SALARY 表数据,但它给了我这个错误

点数模型

public function salarie()
{
    return $this->belongsTo('App\Salarie');
}

薪酬模式

public function pointages()
{
    return $this->hasMany('App\Pointage');
}

迁移迁移 salarie_id

 /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('pointages', function (Blueprint $table) {
            $table->integer('salarie_id')->unsigned()->after('id');
            $table->foreign('salarie_id')->references('id')->on('salaries');  
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('pointages', function (Blueprint $table) {
             $table->dropForeign(['salarie_id']);
            $table->dropCulomn('salarie_id');
        });
    }

薪水 Controller

public function consulter()
{      
    $salaries=Salarie::with('pointage')->get();
    $pointages = DB::table('pointages')->pluck("pointage","id")->all();
    return view('salarie.consulter', compact('salaries', 'pointages'));
}

最佳答案

只需将 with('pointage') 更改为 with('pointages')

关于mysql - 调用模型 [App\Salarie] 上的未定义关系 [pointage]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56925634/

相关文章:

php - 使用 php mysql 数据格式化莫里斯图表中的日期

mysql - 我想从两个表中计数,然后使用总计来划分

database - 迁移中的 Laravel 关系?

mysql - FlywayDB : Migration fails with "Error executing statement", 但手动运行迁移 SQL 代码有效

mysql - 将行与列连接 mysql

php - 恢复mysql数据库报错

php - 将 php 项目移动到 codeigniter 或更新现有框架

Laravel 5.8 Nova 登录测试 session 缺少预期的 key [错误]

mysql - 在 mysql workbench 中启动迁移向导时出现问题

entity-framework - 将 EF Code First 同步到 SQL Azure