简体   繁体   English

Laravel Equolent中数据库中的值多久出现一次

[英]How often is the value in the database in Laravel Equolent

I am beginner.我是初学者。 I have small problem with Laravel Equolent.我对 Laravel Equolent 有一个小问题。

I have migrations:我有迁移:

Schema::create('datas', function (Blueprint $table) {
            $table->id();
            $table->integer('number');
            $table->timestamps();
        });

and model:和型号:

class Data extends Model
{
    protected $guarded = ['id'];

    protected $fillable = [
        'number'
    ];

    protected $dates = [
        'created_at',
        'updated_at',
        'date'
    ];

    protected $casts = [
        'number'=>'integer',
    ];
}

Normalny I make this code: Normalny 我做这个代码:

Data::get();

and this is return me all record from DB.这是从数据库返回给我的所有记录。

I need information how often does the number appear in the database.我需要该数字在数据库中出现的频率。

For example:例如:

Data->where('number', 1)->get();
Data->where('number', 15)->get();
Data->where('number', 55)->get();

etc ETC

how wany can I count this result?我怎么能算这个结果? ->count()? ->计数()?

If you need to count all the records in your Data model, you can use this code:如果您需要统计Data模型中的所有记录,可以使用以下代码:

$count = Data::count();

But if you want to count specific number , try this:但是如果你想计算特定的number ,试试这个:

$count = Data::where('number', $number)->count();

在控制器文件中 Data::count();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM