admin login completed

This commit is contained in:
Abhishek Mali
2025-11-06 17:09:52 +05:30
parent ccbef09484
commit 3c4727acd9
18 changed files with 504 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\Admin;
use Illuminate\Support\Facades\Hash;
class AdminAuthController extends Controller
{
// 🟢 Show login form
public function showLoginForm()
{
return view('admin.login');
}
// 🟢 Handle login request
public function login(Request $request)
{
$request->validate([
'email' => 'required|email',
'password' => 'required|min:6',
]);
$credentials = $request->only('email', 'password');
if (Auth::guard('admin')->attempt($credentials)) {
return redirect()->route('admin.dashboard')->with('success', 'Login successful!');
}
return back()->withErrors(['email' => 'Invalid credentials.'])->withInput();
}
// 🟢 Logout
public function logout(Request $request)
{
Auth::guard('admin')->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect()->route('admin.login')->with('success', 'Logged out successfully.');
}
}

22
app/Models/Admin.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
// app/Models/Admin.php
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class Admin extends Authenticatable
{
use Notifiable;
protected $guard = 'admin';
protected $fillable = [
'name', 'email', 'password', 'role',
];
protected $hidden = [
'password', 'remember_token',
];
}

View File

@@ -45,6 +45,11 @@ return [
'driver' => 'jwt',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
],
@@ -70,6 +75,11 @@ return [
'driver' => 'eloquent',
'model' => env('AUTH_MODEL', App\Models\User::class),
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Models\Admin::class,
],
// 'users' => [
// 'driver' => 'database',

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
// database/migrations/xxxx_xx_xx_create_admins_table.php
public function up()
{
Schema::create('admins', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->enum('role', ['super_admin', 'admin'])->default('admin');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('admins');
}
};

View File

@@ -0,0 +1,39 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::create('requests', function (Blueprint $table) {
$table->id(); // Auto-increment primary key
$table->string('request_id')->unique(); // Custom formatted ID like REQ-2025-000001
$table->string('customer_name');
$table->string('company_name');
$table->string('designation');
$table->string('email')->unique();
$table->string('mobile_no');
$table->string('priority')->nullable();
$table->text('address')->nullable();
$table->string('pincode')->nullable();
$table->date('date')->nullable();
$table->enum('status', ['pending', 'approved', 'rejected'])->default('pending');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('requests');
}
};

View File

@@ -0,0 +1,12 @@
@extends('admin.layouts.app')
@section('page-title', 'account')
@section('content')
<div class="card shadow-sm">
<div class="card-body">
<h4>Welcome to the Admin account</h4>
<p>Here you can manage all system modules.</p>
</div>
</div>
@endsection

View File

@@ -0,0 +1,12 @@
@extends('admin.layouts.app')
@section('page-title', 'Dashboard')
@section('content')
<div class="card shadow-sm">
<div class="card-body">
<h4>Welcome to the Admin chat</h4>
<p>Here you can manage all system modules.</p>
</div>
</div>
@endsection

View File

@@ -0,0 +1,12 @@
@extends('admin.layouts.app')
@section('page-title', 'Dashboard')
@section('content')
<div class="card shadow-sm">
<div class="card-body">
<h4>Welcome to the Admin customer page</h4>
<p>Here you can manage all system modules.</p>
</div>
</div>
@endsection

View File

@@ -0,0 +1,12 @@
@extends('admin.layouts.app')
@section('page-title', 'Dashboard')
@section('content')
<div class="card shadow-sm">
<div class="card-body">
<h4>Welcome to the Admin Dashboard</h4>
<p>Here you can manage all system modules.</p>
</div>
</div>
@endsection

View File

@@ -0,0 +1,12 @@
@extends('admin.layouts.app')
@section('page-title', 'Dashboard')
@section('content')
<div class="card shadow-sm">
<div class="card-body">
<h4>Welcome to the Admin invoice</h4>
<p>Here you can manage all system modules.</p>
</div>
</div>
@endsection

View File

@@ -0,0 +1,130 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Admin Panel</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
<style>
body {
display: flex;
background-color: #f8f9fa;
min-height: 100vh;
}
.sidebar {
width: 250px;
background: #ffffff;
border-right: 1px solid #dee2e6;
flex-shrink: 0;
}
.sidebar .logo {
display: flex;
align-items: center;
padding: 15px;
border-bottom: 1px solid #dee2e6;
}
.sidebar .logo img {
height: 40px;
margin-right: 10px;
}
.sidebar a {
display: flex;
align-items: center;
color: #333;
text-decoration: none;
padding: 10px 20px;
border-radius: 8px;
margin: 4px 10px;
transition: 0.2s;
}
.sidebar a:hover, .sidebar a.active {
background: #e7f1ff;
color: #0d6efd;
}
.sidebar a i {
margin-right: 10px;
font-size: 1.1rem;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
background: #ffffff;
padding: 10px 25px;
border-bottom: 1px solid #dee2e6;
}
.main-content {
flex-grow: 1;
display: flex;
flex-direction: column;
}
.content-wrapper {
padding: 25px;
}
</style>
</head>
<body>
<!-- Sidebar -->
<div class="sidebar">
<div class="logo">
<img src="https://upload.wikimedia.org/wikipedia/commons/4/47/Kent_Ro_Systems_logo.png" alt="Logo">
<div>
<strong>KENT</strong><br>
<small>International Pvt. Ltd.</small>
</div>
</div>
<a href="{{ route('admin.dashboard') }}" class="{{ request()->routeIs('admin.dashboard') ? 'active' : '' }}"><i class="bi bi-house"></i> Dashboard</a>
<a href="{{ route('admin.shipments') }}" class="{{ request()->routeIs('admin.shipments') ? 'active' : '' }}"><i class="bi bi-truck"></i> Shipments</a>
<a href="{{ route('admin.invoice') }}" class="{{ request()->routeIs('admin.invoice') ? 'active' : '' }}"><i class="bi bi-receipt"></i> Invoice</a>
<a href="{{ route('admin.customers') }}" class="{{ request()->routeIs('admin.customers') ? 'active' : '' }}"><i class="bi bi-people"></i> Customers</a>
<a href="{{ route('admin.reports') }}" class="{{ request()->routeIs('admin.reports') ? 'active' : '' }}"><i class="bi bi-graph-up"></i> Reports</a>
<a href="{{ route('admin.chat_support') }}" class="{{ request()->routeIs('admin.chat_support') ? 'active' : '' }}"><i class="bi bi-chat-dots"></i> Chat Support</a>
<a href="{{ route('admin.orders') }}" class="{{ request()->routeIs('admin.orders') ? 'active' : '' }}"><i class="bi bi-bag"></i> Orders</a>
<a href="{{ route('admin.requests') }}" class="{{ request()->routeIs('admin.requests') ? 'active' : '' }}"><i class="bi bi-envelope"></i> Requests</a>
<a href="{{ route('admin.staff') }}" class="{{ request()->routeIs('admin.staff') ? 'active' : '' }}"><i class="bi bi-person-badge"></i> Staff</a>
<a href="{{ route('admin.account') }}" class="{{ request()->routeIs('admin.account') ? 'active' : '' }}"><i class="bi bi-gear"></i> Account</a>
<form method="POST" action="{{ route('admin.logout') }}" class="mt-4 px-3">
@csrf
<button type="submit" class="btn btn-danger w-100"><i class="bi bi-box-arrow-right"></i> Logout</button>
</form>
</div>
<!-- Main Content -->
<div class="main-content">
<!-- Header -->
<header>
<h5>@yield('page-title')</h5>
<div class="d-flex align-items-center gap-3">
<i class="bi bi-bell position-relative fs-4">
<span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">2</span>
</i>
<div class="dropdown">
<a href="#" class="d-flex align-items-center text-decoration-none dropdown-toggle" data-bs-toggle="dropdown">
<img src="https://i.pravatar.cc/40" class="rounded-circle me-2" width="35" height="35">
<span>{{ Auth::guard('admin')->user()->name }}</span>
</a>
<ul class="dropdown-menu dropdown-menu-end">
<li><a class="dropdown-item" href="{{ route('admin.account') }}">My Account</a></li>
<li><hr class="dropdown-divider"></li>
<li>
<form method="POST" action="{{ route('admin.logout') }}">
@csrf
<button class="dropdown-item" type="submit">Logout</button>
</form>
</li>
</ul>
</div>
</div>
</header>
<div class="content-wrapper">
@yield('content')
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<title>Admin Login</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-4">
<div class="card shadow">
<div class="card-header text-center bg-primary text-white">
<h4>Admin Login</h4>
</div>
<div class="card-body">
@if ($errors->any())
<div class="alert alert-danger">
{{ $errors->first() }}
</div>
@endif
<form method="POST" action="{{ route('admin.login.submit') }}">
@csrf
<div class="mb-3">
<label>Email</label>
<input type="email" name="email" class="form-control" value="{{ old('email') }}" required>
</div>
<div class="mb-3">
<label>Password</label>
<input type="password" name="password" class="form-control" required>
</div>
<button type="submit" class="btn btn-primary w-100">Login</button>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,12 @@
@extends('admin.layouts.app')
@section('page-title', 'Dashboard')
@section('content')
<div class="card shadow-sm">
<div class="card-body">
<h4>Welcome to the Admin orders</h4>
<p>Here you can manage all system modules.</p>
</div>
</div>
@endsection

View File

@@ -0,0 +1,12 @@
@extends('admin.layouts.app')
@section('page-title', 'Dashboard')
@section('content')
<div class="card shadow-sm">
<div class="card-body">
<h4>Welcome to the Admin reports</h4>
<p>Here you can manage all system modules.</p>
</div>
</div>
@endsection

View File

@@ -0,0 +1,48 @@
@extends('admin.layouts.app')
@section('page-title', 'User Requests')
@section('content')
<div class="card shadow-sm">
<div class="card-body">
<div class="d-flex justify-content-between align-items-center mb-3">
<input type="text" class="form-control w-50" placeholder="Search Request by name, email, company or ID">
<div>
<span class="badge bg-primary">3 Pending</span>
<span class="badge bg-success">1 Approved</span>
<span class="badge bg-danger">1 Rejected</span>
</div>
</div>
<table class="table table-bordered align-middle">
<thead class="table-light">
<tr>
<th>Request ID</th>
<th>Requester</th>
<th>Company</th>
<th>Type</th>
<th>Priority</th>
<th>Date</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>REQ-2024-001</td>
<td>Amit Patel<br><small>amit.patel@example.com</small></td>
<td>Tech Solutions Pvt. Ltd.</td>
<td><span class="badge bg-info text-dark">New Account</span></td>
<td><span class="badge bg-danger">High</span></td>
<td>2024-09-01</td>
<td><span class="badge bg-warning text-dark">Pending</span></td>
<td>
<i class="bi bi-eye text-primary"></i>
<i class="bi bi-x-circle text-danger ms-2"></i>
</td>
</tr>
</tbody>
</table>
</div>
</div>
@endsection

View File

@@ -0,0 +1,12 @@
@extends('admin.layouts.app')
@section('page-title', 'Dashboard')
@section('content')
<div class="card shadow-sm">
<div class="card-body">
<h4>Welcome to the Admin shipment</h4>
<p>Here you can manage all system modules.</p>
</div>
</div>
@endsection

View File

@@ -0,0 +1,12 @@
@extends('admin.layouts.app')
@section('page-title', 'Dashboard')
@section('content')
<div class="card shadow-sm">
<div class="card-body">
<h4>Welcome to the Admin staff</h4>
<p>Here you can manage all system modules.</p>
</div>
</div>
@endsection

View File

@@ -1,7 +1,34 @@
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AdminAuthController;
// Default welcome page
Route::get('/', function () {
return view('welcome');
});
// -------------------------
// Admin Authentication Routes
// -------------------------
Route::prefix('admin')->group(function () {
Route::get('/login', [AdminAuthController::class, 'showLoginForm'])->name('admin.login');
Route::post('/login', [AdminAuthController::class, 'login'])->name('admin.login.submit');
Route::post('/logout', [AdminAuthController::class, 'logout'])->name('admin.logout');
});
// -------------------------
// Protected Admin Panel Routes
// -------------------------
Route::prefix('admin')->middleware('auth:admin')->group(function () {
Route::get('/dashboard', fn() => view('admin.dashboard'))->name('admin.dashboard');
Route::get('/shipments', fn() => view('admin.shipments'))->name('admin.shipments');
Route::get('/invoice', fn() => view('admin.invoice'))->name('admin.invoice');
Route::get('/customers', fn() => view('admin.customers'))->name('admin.customers');
Route::get('/reports', fn() => view('admin.reports'))->name('admin.reports');
Route::get('/chat-support', fn() => view('admin.chat_support'))->name('admin.chat_support');
Route::get('/orders', fn() => view('admin.orders'))->name('admin.orders');
Route::get('/requests', fn() => view('admin.requests'))->name('admin.requests');
Route::get('/staff', fn() => view('admin.staff'))->name('admin.staff');
Route::get('/account', fn() => view('admin.account'))->name('admin.account');
});