I am beginner in Laravel. I use in my project Laravel 5.8.
I have schema:
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';
});
I get statistics from this function:
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");
};
This code generate statistics. It's work fine. Now I need generate unique visit statistics Unique = unique IP.
How can I make it?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2nIUCXU
via IFTTT
Aucun commentaire:
Enregistrer un commentaire