我有这样一张桌子:
table
- field1: tinyint
- field2: varchar (nullable)
- datefield: timestamp (nullable)
Run Code Online (Sandbox Code Playgroud)
现在我想得到所有条目,其中field1为1,field2为null,其中datefield小于X或null.我已经尝试过这样的事:
$query = Model::where('field1', 1)
->whereNull('field2')
->where('datefield', '<', $date)
->orWhereNull('datefield');
Run Code Online (Sandbox Code Playgroud)
但那不起作用.我总是得到datefield为null的每个条目.其他领域是什么并不重要.我还尝试将它分成2个查询:首先获取datefield小于X或null的每一行然后(基于它)获取field1为1且field2为null的每个字段.
结果是一样的.知道怎么做吗?
这让我疯狂了几个星期:如何在404页面上提供会话?我只是将404错误页面嵌入到我的默认模板中.它还显示了导航栏和页脚,但是如何在404上保持用户登录?
在404 Auth :: check()上总是返回false,其他特定于会话的其他内容为null或为空.
如何在(404)错误页面上启用会话?
我的问题是,我的hasMany关系只返回一个"空"集合:
Collection {#172 ?
#items: array:1 [?
0 => 0
]
}
Run Code Online (Sandbox Code Playgroud)
我的belongsTo关系只返回"null".
以下是雄辩:Game.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\Game
*
* @property integer $id
* @property integer $steamid
* @property string $name
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
*/
class Game extends Model
{
protected $fillable = [
'appid', 'name'
];
public function keys()
{
$this->hasMany('App\Models\Game\Key', 'id', 'game_id');
}
}
Key.php
<?php
namespace App\Models\Game;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\Game\Key
*
*/
class Key extends Model
{ …Run Code Online (Sandbox Code Playgroud)