3 years ago

laravel maatwensite excel import from parent child relationship

Posted 3 years ago by aizaz

use Illuminate\Database\Eloquent\Model;

class Employee extends Model { protected $fillable = ['department_id']; protected $guarded = array('*');

public function bank() { return $this->hasMany('App\Bank'); } } `i want to fetch parent and child model relationships but in a single loop for both parent and child table because maatwebsite-excel export is not working according to its defined scenario AND CHILD MODEL

namespace App;

use Illuminate\Database\Eloquent\Model;

class Bank extends Model { public function employee() { return $this->belongsTo('App\Employee'); } }

and i want simply without nested loop

public function downloadExcel(Employee $employee , $Type) { $data = $employee->with('bank', 'certificate')->get(); foreach ($data as $parentkey => $emp) { $emp->childtable->columname; } } here is the child table structure

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();



Please sign in or create an account to participate in this conversation.