Skip to content

Commit

Permalink
refactor(clean): clean code with js
Browse files Browse the repository at this point in the history
  • Loading branch information
tikrack committed Jan 29, 2025
1 parent ba40941 commit 7644db9
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 24 deletions.
15 changes: 7 additions & 8 deletions app/Http/Controllers/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Models\Code;
use App\Models\User;
use App\Models\Visit;
use Illuminate\Http\Request;

class AdminController extends Controller
{
Expand All @@ -20,15 +19,15 @@ public function index()
$visit_count = Visit::all()->count();

return $this->success([
"codes" => [
"count" => $codes_count
'codes' => [
'count' => $codes_count,
],
"users" => [
"count" => $users_count
'users' => [
'count' => $users_count,
],
'visit' => [
'count' => $visit_count,
],
"visit" => [
"count" => $visit_count
]
]);
}
}
12 changes: 6 additions & 6 deletions app/Http/Controllers/InfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public function info(Request $request)
$code_count = $user?->codes()?->count();

return $this->success([
"user" => [
"name" => $user->name,
"family" => $user->family,
'user' => [
'name' => $user->name,
'family' => $user->family,
],
'code' => [
'count' => $code_count,
],
"code" => [
"count" => $code_count,
]
]);
}
}
5 changes: 3 additions & 2 deletions app/Http/Middleware/CheckAdminMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class CheckAdminMiddleware
{
use ApiResponseTrait;

/**
* Handle an incoming request.
*
Expand All @@ -23,9 +24,9 @@ public function handle(Request $request, Closure $next): Response
$personalAccessToken = $token ? PersonalAccessToken::findToken($token) : null;
$user = $personalAccessToken?->tokenable;

if ($user and $user?->getRoleNames()->toArray()[0] === "admin") {
if ($user and $user?->getRoleNames()->toArray()[0] === 'admin') {
return $next($request);
}else {
} else {
return $this->fail();
}
}
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Middleware/VisitMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class VisitMiddleware
public function handle(Request $request, Closure $next): Response
{
Visit::create([
"ip" => $request->ip(),
"user_agent" => $request->userAgent(),
'ip' => $request->ip(),
'user_agent' => $request->userAgent(),
]);

return $next($request);
}
}
4 changes: 2 additions & 2 deletions app/Models/Visit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Visit extends Model
use SoftDeletes;

protected $fillable = [
"ip",
"user_agent"
'ip',
'user_agent',
];
}
4 changes: 2 additions & 2 deletions database/migrations/2025_01_29_182815_create_visits_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public function up(): void
{
Schema::create('visits', function (Blueprint $table) {
$table->id();
$table->string("ip");
$table->string("user_agent");
$table->string('ip');
$table->string('user_agent');
$table->softDeletes();
$table->timestamps();
});
Expand Down
4 changes: 2 additions & 2 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
Route::delete('code', [CodeController::class, 'destroy'])->name('code');
Route::post('info', [InfoController::class, 'info'])->name('info');

Route::prefix("admin")->name(".admin")->middleware(CheckAdminMiddleware::class)->group(function () {
Route::post("/", [AdminController::class, "index"]);
Route::prefix('admin')->name('.admin')->middleware(CheckAdminMiddleware::class)->group(function () {
Route::post('/', [AdminController::class, 'index']);
});
});
});
Expand Down

0 comments on commit 7644db9

Please sign in to comment.