namespace App;
use Illuminate\Database\Eloquent\Model;
class Employee extends Model
{
protected $fillable = ['department_id'];
protected $guarded = array('*');
public function bank()
{
return $this->hasMany('App\Bank');
}
}
親と子のモデル関係をフェッチしたいが、定義されたシナリオに従って maatwebsite-excel エクスポートが機能しないため、親テーブルと子テーブルの両方に対して 1 つのループで AND CHILD MODEL
namespace App;
use Illuminate\Database\Eloquent\Model;
class Bank extends Model
{
public function employee()
{
return $this->belongsTo('App\Employee');
}
}
ネストされたループなしで単純に欲しい
public function downloadExcel(Employee $employee , $Type)
{
$data = $employee->with('bank', 'certificate')->get();
foreach ($data as $parentkey => $emp) {
$emp->childtable->columname;
}
}
ここに子テーブル構造があります
public function up()
{
Schema::create('bank', function (Blueprint $table) {
$table->increments('id');
$table->integer('emp_id');
$table->string('bankname');
$table->string('branchname');
$table->string('branchcode');
$table->string('acc_code');
$table->string('branchcity');
$table->string('acc_type');
$table->string('cert_created_by');
$table->string('cert_updated_by');
$table->foreign('emp_id')->references('id')->on('employees');
$table->timestamps();
});
}