我在表服务器中有2列.
我有专栏ip和hostname.
我有验证:
'data.ip' => ['required', 'unique:servers,ip,'.$this->id]
Run Code Online (Sandbox Code Playgroud)
这仅适用于列ip.但是如何做到这一点hostname呢?
我想要使用列ip和hostname.验证data.ip.因为在ip和hostname列中可以重复,当用户写ip时.
如何momentjs为用户实时更新相对时间?
我计算过:
computed: {
ago() {
return moment().fromNow();
},
}
Run Code Online (Sandbox Code Playgroud)
当我在组件中使用时:
<span class="text-muted pr-2" v-text="ago"></span>
Run Code Online (Sandbox Code Playgroud)
我得到静态文本:a few seconds ago,如何在不重新加载页面的情况下更新此文本?我想看:a minute ago,atwo minutes ago等。
我如何为用户实时执行此操作?
我有元素侧边栏和 div 类sticky-top:
<div class="row">
<div class="col-lg-4">
<div class="sticky-top">
....
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
当侧边栏是粘性的时,我需要传递一个边距,因为粘性顶部类没有边距顶部。
当侧边栏有粘性时如何写边距?
我如何检查是否在Laravel 5.7中验证了电子邮件?
我想,这可能与:
if(!Auth::user()->email_verified_at) {
return 'Email not verified!';
}
Run Code Online (Sandbox Code Playgroud)
还是有其他方法吗?
我如何在 Laravel 地图函数中继续循环?
我有代码:
return collect($response->rows ?? [])->map(function (array $userRow) {
if ($userRow[0] == 'Returning Visitor') {
return [
$userRow[1] => [
'type' => $userRow[0],
'sessions' => (int) $userRow[2],
]
];
} else {
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
和输出:
Collection {#986 ?
#items: array:4 [?
0 => false
1 => false
2 => array:1 [?]
3 => array:1 [?]
]
}
Run Code Online (Sandbox Code Playgroud)
我不需要 params false,我需要继续它或删除它。我该如何解决这个问题?
我有收藏:
\n\n$categories = $post->categories;\nRun Code Online (Sandbox Code Playgroud)\n\n我明白了:
\n\n#items: array:1 [\xe2\x96\xbc\n 0 => Category {#999 \xe2\x96\xb6}\n 1 => Category {#999 \xe2\x96\xb6}\n]\nRun Code Online (Sandbox Code Playgroud)\n\n我需要从类别中获取id。
我试试这个:
\n\n$categories = array_column('id', $post->categories);\nRun Code Online (Sandbox Code Playgroud)\n\n但集合array_column不起作用。我怎样才能做到这一点?
我想要做百分比列..
我需要写:1.00, 2.00, 99.99, 100.. %
我如何为此使用双精度类型?
我现在有:
Double(4,2)
Run Code Online (Sandbox Code Playgroud)
但是当我在列中写入 100 时,出现错误:
数值超出范围:1264 列的值超出范围
我有一系列的收藏。在收藏中我有关系。我如何whereIn在这些关系中使用?
$arrayCollections = $category->products;
$arrayCollections = $arrayCollections->character->whereIn('id', [1,2,3,4]); //I need use whereIn in character relation. I get error: Property [character] does not exist on this collection instance.
foreach($arrayCollections as $product) {
.... //but in foreach I can use $product->character
}
Run Code Online (Sandbox Code Playgroud)
与产品型号的关系::
public function character()
{
return $this->hasMany('App\Models\ProductCharacter');
}
Run Code Online (Sandbox Code Playgroud) 我有带复选框的表格
@foreach($accounts as $acc)
<input type="checkbox" value="1" name="account[{{ $acc->id }}]" @if($acc->published) checked @endif>
@endforeach
Run Code Online (Sandbox Code Playgroud)
未选中复选框时如何传递 0 值?
我的控制器:
public function updateMon(Request $request) {
$request->validate([
'account' => 'required|array',
'account.*' => 'integer'
]);
foreach($account as $acc => $val) {
dd($val); //how get 0?
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个列的表标记:user_id,token,expires_at。
例:
我有令牌:12345,对我来说,他过期于:2018-06-05
生成新令牌时,最多生成7天。
我该如何检查模型?
我试着做模型的范围:
public function scopeExpired($query) {
return $this->where('expires_at', '<=', Carbon::now())->exists();
}
Run Code Online (Sandbox Code Playgroud)
但是没有用。总是假..
我有模型产品,在表产品中我有列discount和列price。如何更新型号中的折扣价格?并获取实际价格和旧价格?我有功能:
class Product extends Model
{
protected $guarded = [];
public function getPriceAttribute() {
return $this->price * (1 - $this->discount / 100);
}
}
Run Code Online (Sandbox Code Playgroud)
通过属性,price我可以获得更新的价格,但是如何获得该产品的旧价格?
laravel ×8
php ×8
javascript ×2
css ×1
html ×1
laravel-5.7 ×1
momentjs ×1
mysql ×1
vue.js ×1
vuejs2 ×1