我正在使用Laravel Framework 6.16.0并且有两个表,logos并且companies:
标志:
Schema::create('logos', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('companies_id')->default('999999');
$table->string('logo_path')->nullable($value = true); // path to the logo image
$table->timestamps();
});
公司:
Schema::create('companies', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('symbol'); // AAPL
$table->string('name'); // company name such as Apple Inc.
$table->timestamps();
});
楷模:
class Logo extends Model
{
protected $table = 'logos';
protected $guarded = ['id'];
public function company()
{
return $this->belongsTo(Company::class, 'companies_id');
}
}
class Company extends Model
{
protected $table = 'companies';
protected $guarded = ['id'];
}
我想获取 中没有徽标logo-table且徽标尚未更新的所有符号90 days。
我尝试了以下方法:
$symbolsWithoutLogos = DB::table('companies')
>leftJoin('logos', 'companies.id', '=', 'logos.companies_id')
->whereDate('logos.updated_at', Carbon::now()->subDays(90))
->whereNull('companies.logo_image')
->orderBy('name', 'ASC')
->get('companies.*');
该查询的结果是:
select `companies`.* from `companies` left join `logos` on `companies`.`id` = `logos`.`companies_id` where date(`logos`.`updated_at`) = ? order by `name` asc
但是,即使我的公司表有足够的记录,运行此查询时我也得不到结果:
有什么建议我做错了什么吗?
我很感谢你的回复!
森栏
德玛西亚99