小编sgt*_*sco的帖子

Laravel - 从请求中过滤掉“空”值

我试图过滤我的$request不包含任何字段为qty空的输入数据(qty位于数据透视表上)

我已经尝试过:

$qty = $request->input('qty'); //define qty

$filtered = $request->filter(function ($qty, $key) {
   return $qty != null;
});

$filtered->all();
Run Code Online (Sandbox Code Playgroud)

但我收到错误Method Illuminate\Http\Request::filter does not exist,这很奇怪,因为我use Illuminate\Http\Request;在控制器中。

虽然我以前从未过滤过数据,所以我不知道这是否是正确的方法。

filter laravel laravel-5

2
推荐指数
1
解决办法
2485
查看次数

Laravel - 时间戳字段被读取为字符串

我的数据库中有一个自定义时间戳字段, delivery_date

$table->timestamp('delivery_date')->nullable();
Run Code Online (Sandbox Code Playgroud)

每当我尝试使用此字段时,它都会将其作为字符串引入...

"2018-12-17 00:00:00"
Run Code Online (Sandbox Code Playgroud)

但是created_at,例如,如果我使用带有时间戳的相同代码,则会将其作为时间戳引入。

date: 2018-12-09 00:00:00.0 America/New_York (-05:00)

我曾试图改变迁移外地datetime,并date具有相同的结果。

我也尝试通过...转换结果

strtotime($order->delivery_date)
Run Code Online (Sandbox Code Playgroud)

但出于某种原因,它将其转换为整数。

php timestamp laravel

2
推荐指数
1
解决办法
1120
查看次数

标签 统计

laravel ×2

filter ×1

laravel-5 ×1

php ×1

timestamp ×1