I have two Models
TermOne
<?php
namespace App;
use IlluminateDatabaseEloquentModel;
class TermOne extends Model
{
public function term_one_files()
{
return $this->hasMany('AppTermOneFile');
}
}
I want to get values of this Model
<?php
namespace App;
use IlluminateDatabaseEloquentModel;
class TermOneFile extends Model
{
public function term_ones()
{
return $this->belongsTo('AppTermOne');
}
}
I want to get the table two values TermOneFile form TermOne with eager loading but I get this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'term_one_files.term_one_id' in 'where clause' (SQL: select * from term_one_files where term_one_files.term_one_id in (1))
here is my Controller
$curriculum = TermOne::with('term_one_files')->where('id', $request->curriculum_id)->get();
dd($curriculum);
return view('backend.uploads.index', compact('grade', 'subject', 'term_id', 'curriculum'));
maybe Im doing something wrong
term_one_files structure
public function up()
{
Schema::create('term_one_files', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('curriculum_id');
$table->string('filename')->nullable();
$table->string('filepath')->nullable();
$table->timestamps();
$table->foreign('curriculum_id')->references('id')->on('term_ones')
->onUpdate('cascade')->onDelete('cascade');
});
}
question from:
https://stackoverflow.com/questions/65874282/how-to-get-the-second-table-values-in-one-to-many-relationship 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…