Compare commits
2 Commits
9dee1a4eed
...
b7085f81ab
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
b7085f81ab | ||
|
|
7c7ac7683a |
34
app/Http/Controllers/Admin/AdminMarkListController.php
Normal file
34
app/Http/Controllers/Admin/AdminMarkListController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\MarkList;
|
||||
|
||||
class AdminMarkListController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show all mark list entries in descending order (latest first)
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$markList = MarkList::orderBy('id', 'desc')->get();
|
||||
|
||||
return view('admin.mark_list', compact('markList'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle status between Active and Inactive
|
||||
*/
|
||||
public function toggleStatus($id)
|
||||
{
|
||||
$mark = MarkList::findOrFail($id);
|
||||
|
||||
// Toggle logic
|
||||
$mark->status = $mark->status === 'active' ? 'inactive' : 'active';
|
||||
$mark->save();
|
||||
|
||||
return redirect()->back()->with('success', 'Status updated successfully!');
|
||||
}
|
||||
}
|
||||
95
app/Http/Controllers/MarkListController.php
Normal file
95
app/Http/Controllers/MarkListController.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\MarkList;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use PHPOpenSourceSaver\JWTAuth\Facades\JWTAuth;
|
||||
|
||||
class MarkListController extends Controller
|
||||
{
|
||||
/**
|
||||
* Add new Mark No (entered by user)
|
||||
*/
|
||||
public function addmarkno(Request $request)
|
||||
{
|
||||
try {
|
||||
// Validate input
|
||||
$request->validate([
|
||||
'mark_no' => 'required|string|max:255|unique:mark_list,mark_no',
|
||||
'origin' => 'required|string|max:255',
|
||||
'destination' => 'required|string|max:255',
|
||||
]);
|
||||
} catch (\Illuminate\Validation\ValidationException $e) {
|
||||
// Check if the mark_no uniqueness failed
|
||||
if (isset($e->validator->failed()['mark_no']['Unique'])) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Mark No already taken by another customer.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Default validation error
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage()
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Authenticate user via JWT
|
||||
$user = JWTAuth::parseToken()->authenticate();
|
||||
|
||||
if (!$user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Unauthorized'
|
||||
], 401);
|
||||
}
|
||||
|
||||
// Create mark record
|
||||
$mark = MarkList::create([
|
||||
'mark_no' => $request->mark_no,
|
||||
'origin' => $request->origin,
|
||||
'destination' => $request->destination,
|
||||
'customer_id' => $user->customer_id,
|
||||
'customer_name' => $user->customer_name,
|
||||
'company_name' => $user->company_name,
|
||||
'mobile_no' => $user->mobile_no,
|
||||
'date' => Carbon::now()->toDateString(),
|
||||
'status' => 'active',
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Mark No added successfully.',
|
||||
'data' => $mark
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show all marks for the logged-in user
|
||||
*/
|
||||
public function showmarklist()
|
||||
{
|
||||
$user = JWTAuth::parseToken()->authenticate();
|
||||
|
||||
if (!$user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Unauthorized'
|
||||
], 401);
|
||||
}
|
||||
|
||||
$marks = MarkList::where('customer_id', $user->customer_id)
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $marks
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -2,28 +2,24 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MarkList extends Model
|
||||
{
|
||||
protected $table = 'mark_lists';
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'mark_list';
|
||||
|
||||
protected $fillable = [
|
||||
'mark_no', // e.g., MARK-2025-000001
|
||||
'mark_no',
|
||||
'origin',
|
||||
'destination',
|
||||
'customer_name',
|
||||
'mobile_no',
|
||||
'customer_id',
|
||||
'customer_name',
|
||||
'company_name',
|
||||
'mobile_no',
|
||||
'date',
|
||||
'status',
|
||||
'status'
|
||||
];
|
||||
|
||||
/**
|
||||
* Relationship: each mark list belongs to a customer (user)
|
||||
*/
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'customer_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<?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('mark_lists', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
// Order as requested:
|
||||
$table->string('mark_no');
|
||||
$table->string('origin');
|
||||
$table->string('destination');
|
||||
$table->string('customer_name');
|
||||
$table->string('mobile_no');
|
||||
$table->unsignedBigInteger('customer_id');
|
||||
$table->date('date')->nullable();
|
||||
$table->enum('status', ['active', 'inactive'])->default('active');
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
// Foreign key constraint
|
||||
$table->foreign('customer_id')
|
||||
->references('id')
|
||||
->on('users')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('mark_lists');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::create('mark_list', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('mark_no')->unique();
|
||||
$table->string('origin');
|
||||
$table->string('destination');
|
||||
$table->string('customer_id');
|
||||
$table->string('customer_name');
|
||||
$table->string('company_name')->nullable();
|
||||
$table->string('mobile_no');
|
||||
$table->date('date')->nullable();
|
||||
$table->enum('status', ['active', 'inactive'])->default('active');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('mark_list');
|
||||
}
|
||||
};
|
||||
@@ -85,6 +85,7 @@
|
||||
<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>
|
||||
<a href="{{ route('admin.marklist.index') }}" class="{{ request()->routeIs('admin.marklist.index') ? 'active' : '' }}"><i class="bi bi-gear"></i> mark_list</a>
|
||||
|
||||
<form method="POST" action="{{ route('admin.logout') }}" class="mt-4 px-3">
|
||||
@csrf
|
||||
|
||||
60
resources/views/admin/mark_list.blade.php
Normal file
60
resources/views/admin/mark_list.blade.php
Normal file
@@ -0,0 +1,60 @@
|
||||
@extends('admin.layouts.app')
|
||||
|
||||
@section('page-title', 'Mark List')
|
||||
|
||||
@section('content')
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<h4 class="mb-3">Mark List Management</h4>
|
||||
|
||||
@if(session('success'))
|
||||
<div class="alert alert-success">{{ session('success') }}</div>
|
||||
@endif
|
||||
|
||||
<table class="table table-bordered table-hover align-middle">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Mark No</th>
|
||||
<th>Origin</th>
|
||||
<th>Destination</th>
|
||||
<th>Customer Name</th>
|
||||
<th>Mobile</th>
|
||||
<th>Date</th>
|
||||
<th>Status</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse($markList as $index => $mark)
|
||||
<tr>
|
||||
<td>{{ $mark->id }}</td>
|
||||
<td>{{ $mark->mark_no }}</td>
|
||||
<td>{{ $mark->origin }}</td>
|
||||
<td>{{ $mark->destination }}</td>
|
||||
<td>{{ $mark->customer_name }}</td>
|
||||
<td>{{ $mark->mobile_no }}</td>
|
||||
<td>{{ \Carbon\Carbon::parse($mark->date)->format('d-m-Y') }}</td>
|
||||
<td>
|
||||
@if($mark->status == 'active')
|
||||
<span class="badge bg-success">Active</span>
|
||||
@else
|
||||
<span class="badge bg-danger">Inactive</span>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
<a href="{{ route('admin.marklist.toggle', $mark->id) }}" class="btn btn-sm btn-primary">
|
||||
{{ $mark->status == 'active' ? 'Deactivate' : 'Activate' }}
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="9" class="text-center text-muted">No mark numbers found.</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -3,10 +3,18 @@
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Controllers\RequestController;
|
||||
use App\Http\Controllers\UserAuthController;
|
||||
use App\Http\Controllers\MarkListController;
|
||||
|
||||
//user send request
|
||||
Route::post('/signup-request', [RequestController::class, 'usersignup']);
|
||||
|
||||
//login / logout
|
||||
Route::post('/user/login', [UserAuthController::class, 'login']);
|
||||
Route::post('/user/logout', [UserAuthController::class, 'logout'])->middleware('auth:api');
|
||||
Route::post('/user/logout', [UserAuthController::class, 'logout'])->middleware('auth:api');
|
||||
|
||||
|
||||
|
||||
Route::middleware(['auth:api'])->group(function () {
|
||||
Route::get('/show-mark-list', [MarkListController::class, 'showmarklist']); // Fetch all marks by user
|
||||
Route::post('/add-mark-no', [MarkListController::class, 'addmarkno']); // Create new mark
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Controllers\Admin\AdminAuthController;
|
||||
use App\Http\Controllers\Admin\UserRequestController;
|
||||
use App\Http\Controllers\Admin\AdminMarkListController;
|
||||
|
||||
// -------------------------
|
||||
// Default Front Page
|
||||
@@ -34,9 +35,14 @@ Route::prefix('admin')->middleware('auth:admin')->group(function () {
|
||||
Route::get('/orders', fn() => view('admin.orders'))->name('admin.orders');
|
||||
Route::get('/staff', fn() => view('admin.staff'))->name('admin.staff');
|
||||
Route::get('/account', fn() => view('admin.account'))->name('admin.account');
|
||||
|
||||
|
||||
// ✅ User Requests Controller Routes
|
||||
Route::get('/requests', [UserRequestController::class, 'index'])->name('admin.requests');
|
||||
Route::get('/requests/approve/{id}', [UserRequestController::class, 'approve'])->name('admin.requests.approve');
|
||||
Route::get('/requests/reject/{id}', [UserRequestController::class, 'reject'])->name('admin.requests.reject');
|
||||
|
||||
//mark list show
|
||||
Route::get('/mark-list', [AdminMarkListController::class, 'index'])->name('admin.marklist.index');
|
||||
Route::get('/mark-list/status/{id}', [AdminMarkListController::class, 'toggleStatus'])->name('admin.marklist.toggle');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user