TASKS ДОПОЛНЕНИЯ 15‐19 - RadLeoOFC/laravel-admin-panel GitHub Wiki

Report on Fixing and Improving the Admin Panel Interface and Logic

1. Issue with Navigation in the Admin Panel

Initial Problem Statement:

"Is it normal that on the main page it says dashboard, but when clicking on the Admin Panel button, it redirects to main?"

Steps Taken:

  1. Analyzed the navigation behavior:

    • The sidebar Admin Panel button redirected to /dashboard.
    • The header Admin Panel button redirected to /main.
    • The main page displayed the title Dashboard, which was misleading.
  2. Checked routes in routes/web.php:

    • Ensured that the /dashboard and /main routes were correctly defined.
    • Confirmed that the wrong title was being displayed on the main page.
  3. Implemented Fixes:

    • Updated the title on the main page to correctly display Main instead of Dashboard.
    • Ensured that sidebar navigation and header buttons led to the expected destinations.

Result:


✅ The navigation logic is now consistent. The Admin Panel button in the sidebar leads to the Dashboard, while the Admin Panel button in the header leads to Main.
✅ The page titles now correctly reflect their content.

Insert Screenshot: Navigation before the fix
(Скриншот: Главная страница с неправильным заголовком)

Insert Screenshot: Navigation after the fix
(Скриншот: Исправленный заголовок и корректная навигация)


2. Restricting Users from Setting Prices in Memberships

Problem Statement:

"A regular user can manually enter or edit the price field in a membership. Is this behavior correct?"

Steps Taken:

  1. Added automatic price calculation in MembershipController.php:

    private function calculateMembershipPrice($type, $startDate, $endDate)
    {
        $start = \Carbon\Carbon::parse($startDate);
        $end = \Carbon\Carbon::parse($endDate);
        $days = $start->diffInDays($end);
    
        if ($type === 'daily') return $days * 5; // $5 per day
        if ($type === 'monthly') return ceil($days / 30) * 100; // $100 per month
        if ($type === 'yearly') return ceil($days / 365) * 1000; // $1000 per year
    
        return 0;
    }
  2. Modified views (create.blade.php, edit.blade.php):

    • Removed the price input field for non-admin users in the create form.
    • Made the price field readonly for non-admins in the edit form.

Result:


✅ Now, only admins can modify the price.
✅ The price is automatically calculated based on the membership duration.

Insert Screenshot: Before fix (user could edit price)
(Скриншот: Форма с возможностью изменения цены)

Insert Screenshot: After fix (price field removed or read-only for users)
(Скриншот: Форма после исправления)


3. Retaining Form Data on Validation Errors

Problem Statement:

"When a validation error occurs, the selected desk and membership type values are not retained in the form."

Steps Taken:

  1. Identified the issue in create.blade.php:

    <select name="desk_id" id="desk_id" class="form-select" value="{{ old('desk_id') }}"/>
    • The value attribute in select does not work as expected.
  2. Implemented Fix:

    • Updated the select elements to correctly retain the previous input:
    <select name="desk_id" id="desk_id" class="form-select">
        @foreach($desks as $desk)
            <option value="{{ $desk->id }}" {{ old('desk_id') == $desk->id ? 'selected' : '' }}>
                {{ $desk->name }}
            </option>
        @endforeach
    </select>
    • The same fix was applied to the membership_type field.

Result:


✅ Now, selected values remain after validation errors, preventing users from re-entering data.

Insert Screenshot: Before fix (values reset on validation error)
(Скриншот: Ошибки валидации с пустыми полями)

Insert Screenshot: After fix (values retained after validation error)
(Скриншот: Ошибки валидации, но данные сохранены)


⚠️ **GitHub.com Fallback** ⚠️