Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
"require": {
"php": "^8.4",
"illuminate/contracts": "^12.0",
"illuminate/support": "^12.0",
"illuminate/http": "^12.0",
"spatie/laravel-package-tools": "^1.16"
"illuminate/support": "^12.0",
"spatie/laravel-package-tools": "^1.16",
"spatie/laravel-stats": "^2.3"
},
"require-dev": {
"laravel/pint": "^1.14",
Expand Down
34 changes: 34 additions & 0 deletions src/Concerns/HasStatsAfterEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Concerns;

use Illuminate\Database\Eloquent\Model;
use Spatie\Stats\Models\StatsEvent;
use Spatie\Stats\StatsQuery;
use Spatie\Stats\StatsWriter;

trait HasStatsAfterEvents
{
public static function bootStatsAfterEvents()
{
static::created(function (Model $model) {
dispatch(fn() => StatsWriter::for(StatsEvent::class, ['name' => $model::statsClass()])->increase());
});

static::deleted(function (Model $model) {
dispatch(fn() => StatsWriter::for(StatsEvent::class, ['name' => $model::statsClass()])->decrease());
});
}

public static function statsQuery(): StatsQuery
{
return StatsQuery::for(StatsEvent::class, [
'name' => static::statsClass(),
]);
}

public static function statsClass(): string
{
return static::class;
}
}
15 changes: 15 additions & 0 deletions src/Libraries/helpers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Illuminate\Support\Str;
use Illuminate\Support\Facades\Http;

if (! function_exists('timezone')) {
Expand Down Expand Up @@ -39,3 +40,17 @@ function zuck(): array
: [];
}
}

if (! function_exists('toSafeFileName')) {
/**
* convert a string to a safe string for file download string
*/
function toSafeFileName(string $string): string
{
return Str::of($string)
->ascii()
->replace(['/', '\\', ':', '*', '?', '"', '<', '>', '|'], '-')
->trim()
->toString();
}
}
19 changes: 19 additions & 0 deletions src/Middleware/IsDeveloper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class IsDeveloper
{
public function handle(Request $request, Closure $next): Response
{
if (auth()->check() && ! auth()->user()->is_dev) {
abort(403);
}

return $next($request);
}
}
7 changes: 7 additions & 0 deletions src/Stats/LoginStat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace App\Stats;

use Spatie\Stats\BaseStats;

class LoginStat extends BaseStats {}