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
21 changes: 21 additions & 0 deletions app/Exceptions/PermissionConfigurationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Exceptions;

use Exception;

class PermissionConfigurationException extends Exception {
public static function configNotLoaded(): self {
return new self('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
}

public static function teamForeignKeyNotLoaded(): self {
return new self('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
}

public static function configNotFoundForDown(): self {
return new self('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
}
}
9 changes: 0 additions & 9 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ class HandleInertiaRequests extends Middleware {
*/
protected $rootView = 'app';

/**
* Determines the current asset version.
*
* @see https://inertiajs.com/asset-versioning
*/
public function version(Request $request): ?string {
return parent::version($request);
}

/**
* Define the props that are shared by default.
*
Expand Down
4 changes: 2 additions & 2 deletions app/Policies/UserPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function viewAny(User $user): bool {
return $user->can(PermissionsEnum::VIEW_USERS->value);
}

public function view(User $user, User $model): bool {
public function view(User $user): bool {
return $user->can(PermissionsEnum::VIEW_USERS->value);
}

Expand Down Expand Up @@ -49,7 +49,7 @@ public function delete(User $user, User $model): bool {
return $user->can(PermissionsEnum::DELETE_USERS->value);
}

public function restore(User $user, User $model): bool {
public function restore(User $user): bool {
return $user->can(PermissionsEnum::RESTORE_USERS->value);
}
}
12 changes: 7 additions & 5 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Support\Str;

$DEFAULT_HOST = '127.0.0.1';

return [

/*
Expand Down Expand Up @@ -47,7 +49,7 @@
'mysql' => [
'driver' => 'mysql',
'url' => env('DB_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'host' => env('DB_HOST', $DEFAULT_HOST),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'laravel'),
'username' => env('DB_USERNAME', 'root'),
Expand All @@ -67,7 +69,7 @@
'mariadb' => [
'driver' => 'mariadb',
'url' => env('DB_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'host' => env('DB_HOST', $DEFAULT_HOST),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'laravel'),
'username' => env('DB_USERNAME', 'root'),
Expand All @@ -87,7 +89,7 @@
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DB_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'host' => env('DB_HOST', $DEFAULT_HOST),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'laravel'),
'username' => env('DB_USERNAME', 'root'),
Expand Down Expand Up @@ -155,7 +157,7 @@

'default' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'host' => env('REDIS_HOST', $DEFAULT_HOST),
'username' => env('REDIS_USERNAME'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', '6379'),
Expand All @@ -164,7 +166,7 @@

'cache' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'host' => env('REDIS_HOST', $DEFAULT_HOST),
'username' => env('REDIS_USERNAME'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', '6379'),
Expand Down
8 changes: 5 additions & 3 deletions config/logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Monolog\Handler\SyslogUdpHandler;
use Monolog\Processor\PsrLogMessageProcessor;

$DEFAULT_LOG_PATH = 'logs/laravel.log';

return [

/*
Expand Down Expand Up @@ -62,14 +64,14 @@

'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'path' => storage_path($DEFAULT_LOG_PATH),
'level' => env('LOG_LEVEL', 'debug'),
'replace_placeholders' => true,
],

'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'path' => storage_path($DEFAULT_LOG_PATH),
'level' => env('LOG_LEVEL', 'debug'),
'days' => env('LOG_DAILY_DAYS', 14),
'replace_placeholders' => true,
Expand Down Expand Up @@ -126,7 +128,7 @@
],

'emergency' => [
'path' => storage_path('logs/laravel.log'),
'path' => storage_path($DEFAULT_LOG_PATH),
],

],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Exceptions\PermissionConfigurationException;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Expand All @@ -8,6 +9,7 @@
/**
* Run the migrations.
*/
// NOSONAR
public function up(): void {
$teams = config('permission.teams');
$tableNames = config('permission.table_names');
Expand All @@ -16,10 +18,10 @@ public function up(): void {
$pivotPermission = $columnNames['permission_pivot_key'] ?? 'permission_id';

if (empty($tableNames)) {
throw new \Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
throw PermissionConfigurationException::configNotLoaded();
}
if ($teams && empty($columnNames['team_foreign_key'] ?? null)) {
throw new \Exception('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
throw PermissionConfigurationException::teamForeignKeyNotLoaded();
}

Schema::create($tableNames['permissions'], static function (Blueprint $table) {
Expand Down Expand Up @@ -132,7 +134,7 @@ public function down(): void {
$tableNames = config('permission.table_names');

if (empty($tableNames)) {
throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
throw PermissionConfigurationException::configNotFoundForDown();
}

Schema::drop($tableNames['role_has_permissions']);
Expand Down
2 changes: 1 addition & 1 deletion database/seeders/RolesAndPermissionsSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function run(): void {
// create roles using RolesEnum
$admin_role = Role::firstOrCreate(['name' => RolesEnum::ADMINISTRATOR->value, 'guard_name' => 'web']);
$user_manager_role = Role::firstOrCreate(['name' => RolesEnum::USER_MANAGER->value, 'guard_name' => 'web']);
$registered_user_role = Role::firstOrCreate(['name' => RolesEnum::REGISTERED_USER->value, 'guard_name' => 'web']);
Role::firstOrCreate(['name' => RolesEnum::REGISTERED_USER->value, 'guard_name' => 'web']);
// flush cache after creating roles and permissions
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();

Expand Down
2 changes: 1 addition & 1 deletion resources/js/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createRoot } from 'react-dom/client';
import { initializeTheme } from './hooks/use-appearance';

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
const appName = import.meta.env.VITE_APP_NAME ?? 'Laravel';

createInertiaApp({
title: (title) => `${title} - ${appName}`,
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/app-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface AppContentProps extends React.ComponentProps<'main'> {
variant?: 'header' | 'sidebar';
}

export function AppContent({ variant = 'header', children, ...props }: AppContentProps) {
export function AppContent({ variant = 'header', children, ...props }: Readonly<AppContentProps>) {
if (variant === 'sidebar') {
return <SidebarInset {...props}>{children}</SidebarInset>;
}
Expand Down
6 changes: 3 additions & 3 deletions resources/js/components/app-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface AppHeaderProps {
breadcrumbs?: BreadcrumbItem[];
}

export function AppHeader({ breadcrumbs = [] }: AppHeaderProps) {
export function AppHeader({ breadcrumbs = [] }: Readonly<AppHeaderProps>) {
const page = usePage<SharedData>();
const { auth } = page.props;
const getInitials = useInitials();
Expand Down Expand Up @@ -136,9 +136,9 @@ export function AppHeader({ breadcrumbs = [] }: AppHeaderProps) {
<div className="ml-6 hidden h-full items-center space-x-6 lg:flex">
<NavigationMenu className="flex h-full items-stretch">
<NavigationMenuList className="flex h-full items-stretch space-x-2">
{mainNavItems.map((item, index) => (
{mainNavItems.map((item) => (
<NavigationMenuItem
key={index}
key={item.href || item.title}
className="relative flex h-full items-center"
>
<Link
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/app-logo-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function AppLogoIcon(props: ImgHTMLAttributes<HTMLImageElement>)
{...props}
src="/images/logo.png"
alt="App Logo"
className={`w-auto ${props.className || ''}`}
className={`w-auto ${props.className ?? ''}`}
/>
);
}
2 changes: 1 addition & 1 deletion resources/js/components/app-shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface AppShellProps {
variant?: 'header' | 'sidebar';
}

export function AppShell({ children, variant = 'header' }: AppShellProps) {
export function AppShell({ children, variant = 'header' }: Readonly<AppShellProps>) {
const [isOpen, setIsOpen] = useState(() =>
typeof window !== 'undefined' ? localStorage.getItem('sidebar') !== 'false' : true
);
Expand Down
4 changes: 3 additions & 1 deletion resources/js/components/app-sidebar-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { Breadcrumbs } from '@/components/breadcrumbs';
import { SidebarTrigger } from '@/components/ui/sidebar';
import { type BreadcrumbItem as BreadcrumbItemType } from '@/types';

export function AppSidebarHeader({ breadcrumbs = [] }: { breadcrumbs?: BreadcrumbItemType[] }) {
export function AppSidebarHeader({
breadcrumbs = [],
}: Readonly<{ breadcrumbs?: BreadcrumbItemType[] }>) {
return (
<header className="border-sidebar-border/50 group-has-data-[collapsible=icon]/sidebar-wrapper:h-12 flex h-16 shrink-0 items-center gap-2 border-b px-6 transition-[width,height] ease-linear md:px-4">
<div className="flex items-center gap-2">
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { type BreadcrumbItem as BreadcrumbItemType } from '@/types';
import { Link } from '@inertiajs/react';
import { Fragment } from 'react';

export function Breadcrumbs({ breadcrumbs }: { breadcrumbs: BreadcrumbItemType[] }) {
export function Breadcrumbs({ breadcrumbs }: Readonly<{ breadcrumbs: BreadcrumbItemType[] }>) {
return (
<>
{breadcrumbs.length > 0 && (
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/heading-small.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default function HeadingSmall({
title,
description,
}: {
}: Readonly<{
title: string;
description?: string;
}) {
}>) {
return (
<header>
<h3 className="mb-0.5 text-base font-medium">{title}</h3>
Expand Down
5 changes: 4 additions & 1 deletion resources/js/components/heading.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export default function Heading({ title, description }: { title: string; description?: string }) {
export default function Heading({
title,
description,
}: Readonly<{ title: string; description?: string }>) {
return (
<div className="mb-8 space-y-0.5">
<h2 className="text-xl font-semibold tracking-tight">{title}</h2>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ interface IconProps extends Omit<LucideProps, 'ref'> {
iconNode: ComponentType<LucideProps>;
}

export function Icon({ iconNode: IconComponent, className, ...props }: IconProps) {
export function Icon({ iconNode: IconComponent, className, ...props }: Readonly<IconProps>) {
return <IconComponent className={cn('h-4 w-4', className)} {...props} />;
}
2 changes: 1 addition & 1 deletion resources/js/components/nav-footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function NavFooter({
items: NavItem[];
}) {
return (
<SidebarGroup {...props} className={`group-data-[collapsible=icon]:p-0 ${className || ''}`}>
<SidebarGroup {...props} className={`group-data-[collapsible=icon]:p-0 ${className ?? ''}`}>
<SidebarGroupContent>
<SidebarMenu>
{items.map((item) => (
Expand Down
Loading
Loading