So, i have a mongo database filled(21k enteries) with columns like action(there are 5 different actions) id, time, etc.
I need to get the name of every action, and how many times does this action occur. For example: USERPROPERTY_CHANGED - 755
I have tried pretty much everything in here Laravel Eloquent groupBy() AND also return count of each group
Then i tried to make anothe collection, where i input the fields one, by one, and then fetch them, but my migration looks like this:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class actionPopularity extends Migration
{
public function up()
{
Schema::create('actionPopularity', function (Blueprint
$collection) {
$collection->Increments('id');
$collection->string('action');
$collection->integer('count');
});
}
public function down()
{
Schema::dropIfExists('actionPopularity');
}
}
But the collection that this generated had only one field - id.
heres something that kind of works (it shows that it can work with the database)
Controller:
public function database_test()
{
$actions = Action::groupBy('action')->get();
return view('database_test',compact('actions'));
}
view:
{{$actions}}
output:
[{"_id":
{"action":"OBJECT_INSERT"},"action":"OBJECT_INSERT"},
{"_id":
{"action":"OBJECT_MODIFY"},"action":"OBJECT_MODIFY"},
{"_id":
{"action":"null"},"action":"null"},{"_id":
{"action":"USERPROPERTY_CHANGED"},"action":"USERPROPERTY_CHANGED"},
{"_id":{"action":"OBJECT_DELETE"},"action":"OBJECT_DELETE"}]
ultimately i want to get two arrays, one with action names, and another one with the amount of times that this action has been called, to put it in a chart.