Witajcie.
Mam taki kod:
Schema::create('statistics', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('company_id')->unsigned();
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->text('agent')->nullable();
$table->date('date')->nullable();
$table->ipAddress('ip');
$table->bigInteger('user_id')->default(0);
$table->bigInteger('quest_id')->default(0);
$table->string('browser', 70)->nullable();
$table->string('platform', 70)->nullable();
$table->string('language', 12)->nullable();
$table->engine = "InnoDB";
$table->charset = 'utf8mb4';
$table->collation = 'utf8mb4_unicode_ci';
});
Generuje statystyki za pomocą poniższego kodu:
public function generateStatistics(string $dateFrom, string $dateTo, int $id)
{
return Statistics::whereBetween('date', [$dateFrom, $dateTo])->where('user_id', $id)->get();
}
$statisticsTotal = $this->frontendRepository->generateStatistics($dateFrom, $dateTo, $request->user()->id);
$statisticsResultsTotal = [];
$period = CarbonPeriod::create($dateFromInput, '1 day', $dateToInput);
foreach ($period as $dt) {
$date = $dt->format("Y-m-d");
$count = 0;
$count2 = 0;
foreach ($statisticsTotal as $stat){
if ($stat->date == $date){
$count = $count + 1;
}
}
array_push($statisticsResultsTotal, "$date|$count"); };
Powyższy kod generuje mi statystyki poprawnie.
Chciałbym je przerobić na statystyki unikalnych wejść.
Unikalne wejście = unikalne IP.
Wie ktoś może jak to przerobić?