diff --git a/app/Http/Controllers/Admin/AdminMarkListController.php b/app/Http/Controllers/Admin/AdminMarkListController.php new file mode 100644 index 0000000..0747741 --- /dev/null +++ b/app/Http/Controllers/Admin/AdminMarkListController.php @@ -0,0 +1,34 @@ +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!'); + } +} diff --git a/app/Http/Controllers/MarkListController.php b/app/Http/Controllers/MarkListController.php new file mode 100644 index 0000000..9f0b733 --- /dev/null +++ b/app/Http/Controllers/MarkListController.php @@ -0,0 +1,95 @@ +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 + ]); + } +} diff --git a/app/Models/MarkList.php b/app/Models/MarkList.php index 18f3546..edd3e22 100644 --- a/app/Models/MarkList.php +++ b/app/Models/MarkList.php @@ -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'); - } } diff --git a/database/migrations/2025_11_06_131937_create_mark_lists_table.php b/database/migrations/2025_11_06_131937_create_mark_lists_table.php deleted file mode 100644 index dda2f24..0000000 --- a/database/migrations/2025_11_06_131937_create_mark_lists_table.php +++ /dev/null @@ -1,45 +0,0 @@ -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'); - } -}; diff --git a/database/migrations/2025_11_07_105011_create_mark_list_table.php b/database/migrations/2025_11_07_105011_create_mark_list_table.php new file mode 100644 index 0000000..70c2a05 --- /dev/null +++ b/database/migrations/2025_11_07_105011_create_mark_list_table.php @@ -0,0 +1,30 @@ +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'); + } +}; diff --git a/resources/views/admin/layouts/app.blade.php b/resources/views/admin/layouts/app.blade.php index 63df38f..d0c437c 100644 --- a/resources/views/admin/layouts/app.blade.php +++ b/resources/views/admin/layouts/app.blade.php @@ -85,6 +85,7 @@ Requests Staff Account + mark_list