I have 2 tables that use a loadable load, and then use a nested condition in that loadable load:
public function up()
{
Schema::create('leads', function(Blueprint $table)
{
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('first_name',255);
$table->string('surname',255);
});
Schema::table('leads', function($table)
{
$table->foreign('create_by')->references('id')->on('employees')->onDelete('cascade');
});
}
public function up()
{
Schema::create('lead_detail_emails', function(Blueprint $table)
{
$table->engine = 'InnoDB';
$table->increments('id');
$table->integer('lead_id')->unsigned();
$table->string('email',255);
});
Schema::table('lead_detail_emails',function($table)
{
$table->foreign('lead_id')->references('id')->on('leads')->onDelete('cascade');
});
}
class LeadsModel extends Eloquent
{
protected $table = 'leads';
public function emails()
{
return $this->hasMany('LeadDetailEmailsModel','lead_id','id');
}
}
class LeadDetailEmail extends Eloquent
{
protected $table = 'lead_detail_email';
public function lead()
{
return $this->belongsTo('LeadsModel');
}
}
When I try to add a nested condition to the active load, let's say
$qry = LeadsModel::with(
array
(
'emails' => function($qr)
{
$qr->orWhere('email','like','%testname%');
}
));
$res = $qry->get();
dd($res);
It returns all leading records, I tried to combine emails and $ qry using
->join('lead_detail_emails','lead_detail_emails.lead_id','=','leads.id');
but it does not work. can i know what is the problem in the code?
update issue
How can I get links by fulfilling the attached conditions for emails?
Ponce source
share