Project Introduction

The Traffic Management System is an innovative software solution designed to optimize the flow of traffic in urban areas and improve road safety. This system aims to provide real-time monitoring and management of traffic conditions, enabling authorities to make informed decisions and implement effective traffic control measures. With the increasing congestion in cities and the need for efficient transportation systems, the Traffic Management System addresses these challenges by offering a user-friendly interface and robust functionalities for traffic management.

The platform features tools for traffic data collection, analysis, and reporting. It utilizes sensors, cameras, and GPS data to monitor traffic patterns and detect incidents. Users can access real-time information about traffic conditions, road closures, and alternative routes, enhancing their ability to navigate efficiently. Additionally, the system includes predictive analytics to forecast traffic trends and optimize signal timings. By automating these processes, the Traffic Management System aims to reduce congestion, improve travel times, and enhance overall road safety.

Project Objectives

  • To develop an intuitive interface for users to monitor and manage traffic conditions easily.
  • To implement real-time data collection from traffic sensors and cameras.
  • To provide analytics tools for analyzing traffic patterns and identifying congestion points.
  • To enable incident detection and alert systems for timely response by authorities.
  • To facilitate communication between traffic management centers and road users.
  • To generate reports on traffic flow, incidents, and overall system performance.
  • To ensure data security and privacy for all user and traffic information.
  • To enhance user engagement through features like traffic alerts and route recommendations.

Project Modules

User Management Module

  • User Registration/Login: Allow traffic management personnel and authorized users to create accounts and log in securely.
  • Role Management: Differentiate between user roles (e.g., admin, traffic officer, data analyst) with varying permissions.
  • Profile Management: Enable users to manage their profiles and access settings.

Traffic Data Collection Module

  • Sensor Integration: Collect data from various sensors, such as traffic cameras, inductive loop sensors, and radar detectors.
  • GPS Data: Gather real-time location data from vehicles using GPS technology.
  • Mobile Data Collection: Utilize mobile applications to collect traffic data from users (e.g., crowd-sourced data).

Traffic Monitoring Module

  • Real-Time Monitoring: Provide a dashboard for monitoring traffic conditions in real-time, including vehicle counts, speeds, and congestion levels.
  • Incident Detection: Automatically detect traffic incidents (e.g., accidents, road blockages) using sensor data and alerts.
  • Video Surveillance: Integrate video feeds from traffic cameras for visual monitoring and incident verification.

Traffic Control Module

  • Signal Control: Manage traffic signals and optimize their timing based on real-time traffic conditions.
  • Dynamic Signage: Control variable message signs (VMS) to provide real-time information to drivers (e.g., detours, speed limits).
  • Lane Management: Implement lane control strategies, such as reversible lanes or dedicated bus lanes, based on traffic flow.

Traffic Analysis Module

  • Data Analytics: Analyze historical and real-time traffic data to identify patterns, trends, and areas of congestion.
  • Performance Metrics: Calculate key performance indicators (KPIs) such as average speed, travel time, and delay.
  • Simulation and Modeling: Use traffic simulation models to predict the impact of changes in traffic patterns or infrastructure.

Incident Management Module

  • Incident Reporting: Allow users to report traffic incidents and emergencies through the system.
  • Response Coordination: Coordinate responses from emergency services, tow trucks, and traffic management personnel.
  • Post-Incident Analysis: Analyze incidents to identify causes and improve future response strategies.

Public Information Module

  • Traffic Updates: Provide real-time traffic updates to the public through mobile apps, websites, and social media.
  • Route Planning: Offer route planning tools that consider current traffic conditions and suggest alternative routes.
  • Alerts and Notifications: Send alerts to users about traffic incidents, road closures, and construction updates.

Reporting and Visualization Module

  • Custom Reports: Generate reports on traffic patterns, incidents, and system performance for stakeholders.
  • Data Visualization: Provide visual representations of traffic data through charts, graphs, and maps.

Security and Access Control Module

  • Data Security: Ensure that sensitive traffic data is stored securely and access is controlled based on user roles.
  • Incident Response: Implement security measures to protect against cyber threats and unauthorized access.

Project Tables Queries


-- Create Users Table
CREATE TABLE Users (
UserId INT PRIMARY KEY IDENTITY(1,1),
Username NVARCHAR(50) NOT NULL UNIQUE,
PasswordHash NVARCHAR(256) NOT NULL,
Email NVARCHAR(100) NOT NULL UNIQUE,
RoleId INT,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (RoleId) REFERENCES Roles(RoleId)
);
-- Create Roles Table
CREATE TABLE Roles (
RoleId INT PRIMARY KEY IDENTITY(1,1),
RoleName NVARCHAR(50) NOT NULL UNIQUE
);
-- Create TrafficData Table
CREATE TABLE TrafficData (
TrafficDataId INT PRIMARY KEY IDENTITY(1,1),
Location NVARCHAR(100) NOT NULL,
Timestamp DATETIME NOT NULL,
VehicleCount INT NOT NULL,
AverageSpeed DECIMAL(5, 2) NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE()
);
-- Create Incidents Table
CREATE TABLE Incidents (
IncidentId INT PRIMARY KEY IDENTITY(1,1),
Description NVARCHAR(MAX) NOT NULL,
Location NVARCHAR(100) NOT NULL,
Severity NVARCHAR(50) NOT NULL, -- e.g., Minor, Major, Critical
Timestamp DATETIME NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE()
);
-- Create Signals Table
CREATE TABLE Signals (
SignalId INT PRIMARY KEY IDENTITY(1,1),
Location NVARCHAR(100) NOT NULL,
SignalType NVARCHAR(50) NOT NULL, -- e.g., Traffic Light, Stop Sign
Status NVARCHAR(50) NOT NULL, -- e.g., Active, Inactive
CreatedAt DATETIME DEFAULT GETDATE()
);
-- Create PerformanceMetrics Table
CREATE TABLE PerformanceMetrics (
MetricId INT PRIMARY KEY IDENTITY(1,1),
MetricName NVARCHAR(100) NOT NULL,
Value DECIMAL(18, 2) NOT NULL,
Timestamp DATETIME NOT NULL,
CreatedAt DATETIME DEFAULT GETDATE()
);
-- Create Routes Table
CREATE TABLE Routes (
RouteId INT PRIMARY KEY IDENTITY(1,1),
StartLocation NVARCHAR(100) NOT NULL,
EndLocation NVARCHAR(100) NOT NULL,
Distance DECIMAL(10, 2) NOT NULL,
EstimatedTime DECIMAL(10, 2) NOT NULL, -- in minutes
CreatedAt DATETIME DEFAULT GETDATE()
);
-- Create Alerts Table
CREATE TABLE Alerts (
AlertId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
Message NVARCHAR(256) NOT NULL,
IsRead BIT DEFAULT 0,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);
-- Create Reports Table
CREATE TABLE Reports (
ReportId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
ReportDate DATETIME DEFAULT GETDATE(),
Description NVARCHAR(MAX),
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);

Explanation of the Tables

Users: Stores user information, including username, password hash, email, and role.

Roles: Defines user roles (e.g., Admin, Traffic Officer).

TrafficData: Contains traffic data records, including location, timestamp, vehicle count, and average speed.

Incidents: Stores information about traffic incidents, including description, location, severity, and timestamp.

Signals: Manages traffic signals, including location, type, and status.

PerformanceMetrics: Stores performance metrics related to traffic management, including metric name and value.

Routes: Contains information about routes, including start and end locations, distance, and estimated travel time.

Alerts: Manages alerts for users, such as notifications about incidents or traffic conditions.

Reports: Stores reports submitted by users, including description and associated user.

To create the models and migrations for the provided MySQL tables in Laravel 11, you can follow these steps.

Step 1: Create Migrations

You can create migrations using the Artisan command line tool. For each table, you will create a migration file. Here are the migration files based on your SQL schema:

1. Create Users Table Migration


// database/migrations/2023_10_01_000001_create_users_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id('User Id');
$table->string('Username', 50)->unique();
$table->string('PasswordHash', 256);
$table->string('Email', 100)->unique();
$table->foreignId('RoleId')->nullable()->constrained('roles', 'RoleId');
$table->timestamps(0); // CreatedAt and UpdatedAt
});
}
public function down()
{
Schema::dropIfExists('users');
}
}

2. Create Roles Table Migration


// database/migrations/2023_10_01_000002_create_roles_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateRolesTable extends Migration
{
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->id('RoleId');
$table->string('RoleName', 50)->unique();
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('roles');
}
}

3. Create TrafficData Table Migration


// database/migrations/2023_10_01_000003_create_traffic_data_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTrafficDataTable extends Migration
{
public function up()
{
Schema::create('traffic_data', function (Blueprint $table) {
$table->id('TrafficDataId');
$table->string('Location', 100);
$table->timestamp('Timestamp');
$table->integer('VehicleCount');
$table->decimal('AverageSpeed', 5, 2);
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('traffic_data');
}
}

4. Create Incidents Table Migration


// database/migrations/2023_10_01_000004_create_incidents_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateIncidentsTable extends Migration
{
public function up()
{
Schema::create('incidents', function (Blueprint $table) {
$table->id('IncidentId');
$table->text('Description');
$table->string('Location', 100);
$table->string('Severity', 50);
$table->timestamp('Timestamp');
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('incidents');
}
}

5. Create Signals Table Migration


// database/migrations/2023_10_01_000005_create_signals_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSignalsTable extends Migration
{
public function up()
{
Schema::create('signals', function (Blueprint $table) {
$table->id('SignalId');
$table->string('Location', 100);
$table->string('SignalType', 50);
$table->string('Status', 50);
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('signals');
}
}

6. Create PerformanceMetrics Table Migration


// database/migrations/2023_10_01_000006_create_performance_metrics_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePerformanceMetricsTable extends Migration
{
public function up()
{
Schema::create('performance_metrics', function (Blueprint $table) {
$table->id('MetricId');
$table->string('MetricName', 100);
$table->decimal('Value', 18, 2);
$table->timestamp('Timestamp');
$table->timestamps( 0);
});
}
public function down()
{
Schema::dropIfExists('performance_metrics');
}
}

7. Create Routes Table Migration


// database/migrations/2023_10_01_000007_create_routes_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateRoutesTable extends Migration
{
public function up()
{
Schema::create('routes', function (Blueprint $table) {
$table->id('RouteId');
$table->string('StartLocation', 100);
$table->string('EndLocation', 100);
$table->decimal('Distance', 10, 2);
$table->decimal('EstimatedTime', 10, 2);
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('routes');
}
}

8. Create Alerts Table Migration


// database/migrations/2023_10_01_000008_create_alerts_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAlertsTable extends Migration
{
public function up()
{
Schema::create('alerts', function (Blueprint $table) {
$table->id('AlertId');
$table->foreignId('User Id')->nullable()->constrained('users', 'User Id');
$table->string('Message', 256);
$table->boolean('IsRead')->default(0);
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('alerts');
}
}

9. Create Reports Table Migration


// database/migrations/2023_10_01_000009_create_reports_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateReportsTable extends Migration
{
public function up()
{
Schema::create('reports', function (Blueprint $table) {
$table->id('ReportId');
$table->foreignId('User Id')->nullable()->constrained('users', 'User Id');
$table->timestamp('ReportDate')->default(now());
$table->text('Description')->nullable();
$table->timestamps(0);
});
}
public function down()
{
Schema::dropIfExists('reports');
}
}

Step 2: Create Models

Next, create the corresponding Eloquent models for each table. Here are the model classes:

1. User Model


// app/Models/User.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use HasFactory;
protected $table = 'users';
protected $fillable = [
'Username',
'PasswordHash',
'Email',
'RoleId',
];
public function role()
{
return $this->belongsTo(Role::class, 'RoleId');
}
public function alerts()
{
return $this->hasMany(Alert::class, 'User Id');
}
public function reports()
{
return $this->hasMany(Report::class, 'User Id');
}
}

2. Role Model


// app/Models/Role.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
use HasFactory;
protected $table = 'roles';
protected $fillable = [
'RoleName',
];
}

3. TrafficData Model


// app/Models/TrafficData.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class TrafficData extends Model
{
use HasFactory;
protected $table = 'traffic_data';
protected $fillable = [
'Location',
'Timestamp',
'VehicleCount',
'AverageSpeed',
];
}

4. Incident Model


// app/Models/Incident.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Incident extends Model
{
use HasFactory;
protected $table = 'incidents';
protected $fillable = [
'Description',
'Location',
'Severity',
'Timestamp',
];
}

5. Signal Model


// app/Models/Signal.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Signal extends Model
{
use HasFactory;
protected $table = 'signals';
protected $fillable = [
'Location',
'SignalType',
'Status',
];
}

6. PerformanceMetric Model


// app/Models/PerformanceMetric.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PerformanceMetric extends Model
{
use HasFactory;
protected $table = 'performance_metrics';
protected $fillable = [
'MetricName',
'Value',
'Timestamp',
];
}

7. Route Model


// app/Models/Route.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Route extends Model
{
use HasFactory;
protected $table = 'routes';
protected $fillable = [
'StartLocation',
'EndLocation',
'Distance',
'EstimatedTime',
];
}

8. Alert Model


// app/Models/Alert.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Alert extends Model
{
use HasFactory;
protected $table = 'alerts';
protected $fillable = [
'User Id',
'Message',
'IsRead',
];
public function user()
{
return $this->belongsTo(User::class, 'User Id');
}
}

9. Report Model


// app/Models/Report.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Report extends Model
{
use HasFactory;
protected $table = 'reports';
protected $fillable = [
'User Id',
'ReportDate',
'Description',
];
public function user()
{
return $this->belongsTo(User::class, 'User Id');
}
}

Step 3: Run Migrations
After creating the migration files and models, run the migrations using the following command:

php artisan migrate

This will create the tables in your database according to the defined schema.

You can now use the models to interact with the database in your Laravel application.

To create controllers for each model with complete CRUD operations in Laravel, you can use the Artisan command line tool to generate the controllers.

Step 1: Generate Controllers

You can generate a controller for each model using the following command:


php artisan make:controller UserController --resource
php artisan make:controller RoleController --resource
php artisan make:controller TrafficDataController --resource
php artisan make:controller IncidentController --resource
php artisan make:controller SignalController --resource
php artisan make:controller PerformanceMetricController --resource
php artisan make:controller RouteController --resource
php artisan make:controller AlertController --resource
php artisan make:controller ReportController --resource

Step 2: Implement CRUD Operations

Below are the implementations for each controller. Each controller will have methods for the following operations:

index(): Display a listing of the resource.

create(): Show the form for creating a new resource.

store(): Store a newly created resource in storage.

show(): Display the specified resource.

edit(): Show the form for editing the specified resource.

update(): Update the specified resource in storage.

destroy(): Remove the specified resource from storage.

1. UserController


// app/Http/Controllers/UserController.php
namespace App\Http\Controllers;
use App\Models\User;
use App\Models\Role;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function index()
{
$users = User::with('role')->get();
return view('users.index', compact('users'));
}
public function create()
{
$roles = Role::all();
return view('users.create', compact('roles'));
}
public function store(Request $request)
{
$request->validate([
'Username' => 'required|unique:users|max:50',
'PasswordHash' => 'required',
'Email' => 'required|email|unique:users|max:100',
'RoleId' => 'nullable|exists:roles,RoleId',
]);
User::create($request->all());
return redirect()->route('users.index')->with('success', 'User created successfully.');
}
public function show(User $user)
{
return view('users.show', compact('user'));
}
public function edit(User $user)
{
$roles = Role::all();
return view('users.edit', compact('user', 'roles'));
}
public function update(Request $request, User $user)
{
$request->validate([
'Username' => 'required|max:50|unique:users,Username,' . $user->id,
'PasswordHash' => 'required',
'Email' => 'required|email|max:100|unique:users,Email,' . $user->id,
'RoleId' => 'nullable|exists:roles,RoleId',
]);
$user->update($request->all());
return redirect()->route('users.index')->with('success', 'User updated successfully.');
}
public function destroy(User $user)
{
$user->delete();
return redirect()->route('users.index')->with('success', 'User deleted successfully.');
}
}

2. RoleController


// app/Http/Controllers/RoleController.php
namespace App\Http\Controllers;
use App\Models\Role;
use Illuminate\Http\Request;
class RoleController extends Controller
{
public function index()
{
$roles = Role::all();
return view('roles.index', compact('roles'));
}
public function create()
{
return view('roles.create');
}
public function store(Request $request)
{
$request->validate([
'RoleName' => 'required|unique:roles|max:50',
]);
Role::create($request->all());
return redirect()->route('roles.index')->with('success', 'Role created successfully.');
}
public function show(Role $role)
{
return view('roles.show', compact('role'));
}
public function edit(Role $role)
{
return view('roles.edit', compact('role'));
}
public function update(Request $request, Role $role)
{
$request->validate([
'RoleName' => 'required|max:50|unique:roles,RoleName,' . $role->id,
]);
$role->update($request->all());
return redirect()->route('roles.index')->with('success', 'Role updated successfully.');
}
public function destroy(Role $role)
{
$role->delete();
return redirect()->route('roles.index')->with('success ', 'Role deleted successfully.');
}
}

3. TrafficDataController


// app/Http/Controllers/TrafficDataController.php
namespace App\Http\Controllers;
use App\Models\TrafficData;
use Illuminate\Http\Request;
class TrafficDataController extends Controller
{
public function index()
{
$trafficData = TrafficData::all();
return view('traffic_data.index', compact('trafficData'));
}
public function create()
{
return view('traffic_data.create');
}
public function store(Request $request)
{
$request->validate([
'Location' => 'required|max:100',
'Timestamp' => 'required|date',
'VehicleCount' => 'required|integer',
'AverageSpeed' => 'required|numeric',
]);
TrafficData::create($request->all());
return redirect()->route('traffic_data.index')->with('success', 'Traffic data created successfully.');
}
public function show(TrafficData $trafficData)
{
return view('traffic_data.show', compact('trafficData'));
}
public function edit(TrafficData $trafficData)
{
return view('traffic_data.edit', compact('trafficData'));
}
public function update(Request $request, TrafficData $trafficData)
{
$request->validate([
'Location' => 'required|max:100',
'Timestamp' => 'required|date',
'VehicleCount' => 'required|integer',
'AverageSpeed' => 'required|numeric',
]);
$trafficData->update($request->all());
return redirect()->route('traffic_data.index')->with('success', 'Traffic data updated successfully.');
}
public function destroy(TrafficData $trafficData)
{
$trafficData->delete();
return redirect()->route('traffic_data.index')->with('success', 'Traffic data deleted successfully.');
}
}

4. IncidentController


// app/Http/Controllers/IncidentController.php
namespace App\Http\Controllers;
use App\Models\Incident;
use Illuminate\Http\Request;
class IncidentController extends Controller
{
public function index()
{
$incidents = Incident::all();
return view('incidents.index', compact('incidents'));
}
public function create()
{
return view('incidents.create');
}
public function store(Request $request)
{
$request->validate([
'Description' => 'required',
'Location' => 'required|max:100',
'Severity' => 'required|max:50',
'Timestamp' => 'required|date',
]);
Incident::create($request->all());
return redirect()->route('incidents.index')->with('success', 'Incident created successfully.');
}
public function show(Incident $incident)
{
return view('incidents.show', compact('incident'));
}
public function edit(Incident $incident)
{
return view('incidents.edit', compact('incident'));
}
public function update(Request $request, Incident $incident)
{
$request->validate([
'Description' => 'required',
'Location' => 'required|max:100',
'Severity' => 'required|max:50',
'Timestamp' => 'required|date',
]);
$incident->update($request->all());
return redirect()->route('incidents.index')->with('success', 'Incident updated successfully.');
}
public function destroy(Incident $incident)
{
$incident->delete();
return redirect()->route('incidents.index')->with('success', 'Incident deleted successfully.');
}
}

5. SignalController


// app/Http/Controllers/SignalController.php
namespace App\Http\Controllers;
use App\Models\Signal;
use Illuminate\Http\Request;
class SignalController extends Controller
{
public function index()
{
$signals = Signal::all();
return view('signals.index', compact('signals'));
}
public function create()
{
return view('signals.create');
}
public function store(Request $request)
{
$request->validate([
'Location' => 'required|max:100',
'SignalType' => 'required|max:50',
'Status' => 'required|max:50',
]);
Signal::create($request->all());
return redirect()->route('signals.index')->with('success', 'Signal created successfully.');
}
public function show(Signal $signal)
{
return view('signals.show', compact('signal'));
}
public function edit(Signal $signal)
{
return view('signals.edit', compact('signal'));
}
public function update(Request $request, Signal $signal)
{
$request->validate([
'Location' => 'required|max:100',
'SignalType' => ' required|max:50',
'Status' => 'required|max:50',
]);
$signal->update($request->all());
return redirect()->route('signals.index')->with('success', 'Signal updated successfully.');
}
public function destroy(Signal $signal)
{
$signal->delete();
return redirect()->route('signals.index')->with('success', 'Signal deleted successfully.');
}
}

6. PerformanceMetricController


// app/Http/Controllers/PerformanceMetricController.php
namespace App\Http\Controllers;
use App\Models\PerformanceMetric;
use Illuminate\Http\Request;
class PerformanceMetricController extends Controller
{
public function index()
{
$metrics = PerformanceMetric::all();
return view('performance_metrics.index', compact('metrics'));
}
public function create()
{
return view('performance_metrics.create');
}
public function store(Request $request)
{
$request->validate([
'MetricName' => 'required|max:100',
'Value' => 'required|numeric',
'Timestamp' => 'required|date',
]);
PerformanceMetric::create($request->all());
return redirect()->route('performance_metrics.index')->with('success', 'Performance metric created successfully.');
}
public function show(PerformanceMetric $metric)
{
return view('performance_metrics.show', compact('metric'));
}
public function edit(PerformanceMetric $metric)
{
return view('performance_metrics.edit', compact('metric'));
}
public function update(Request $request, PerformanceMetric $metric)
{
$request->validate([
'MetricName' => 'required|max:100',
'Value' => 'required|numeric',
'Timestamp' => 'required|date',
]);
$metric->update($request->all());
return redirect()->route('performance_metrics.index')->with('success', 'Performance metric updated successfully.');
}
public function destroy(PerformanceMetric $metric)
{
$metric->delete();
return redirect()->route('performance_metrics.index')->with('success', 'Performance metric deleted successfully.');
}
}

7. RouteController


// app/Http/Controllers/RouteController.php
namespace App\Http\Controllers;
use App\Models\Route;
use Illuminate\Http\Request;
class RouteController extends Controller
{
public function index()
{
$routes = Route::all();
return view('routes.index', compact('routes'));
}
public function create()
{
return view('routes.create');
}
public function store(Request $request)
{
$request->validate([
'StartLocation' => 'required|max:100',
'EndLocation' => 'required|max:100',
'Distance' => 'required|numeric',
'EstimatedTime' => 'required|numeric',
]);
Route::create($request->all());
return redirect()->route('routes.index')->with('success', 'Route created successfully.');
}
public function show(Route $route)
{
return view('routes.show', compact('route'));
}
public function edit(Route $route)
{
return view('routes.edit', compact('route'));
}
public function update(Request $request, Route $route)
{
$request->validate([
'StartLocation' => 'required|max:100',
'EndLocation' => 'required|max:100',
'Distance' => 'required|numeric',
'EstimatedTime' => 'required|numeric',
]);
$route->update($request->all());
return redirect()->route('routes.index')->with('success', 'Route updated successfully.');
}
public function destroy(Route $route)
{
$route->delete();
return redirect()->route('routes.index')->with('success', 'Route deleted successfully.');
}
}

8. AlertController


// app/Http/Controllers/AlertController.php
namespace App\Http\Controllers;
use App\Models\Alert;
use App\Models\User;
use Illuminate\Http\Request;
class AlertController extends Controller
{
public function index()
{
$alerts = Alert::with('user')->get();
return view('alerts.index', compact('alerts'));
}
public function create()
{
$users = User::all();
return view('alerts.create', compact('users'));
}
public function store(Request $request)
{
$request->validate([
'User Id' => 'nullable|exists:users,User Id',
'Message' => 'required|max:256',
'IsRead' => 'boolean',
]);
Alert::create($request->all());
return redirect()->route('alerts.index')->with('success', 'Alert created successfully.');
}
public function show(Alert $alert)
{
return view('alerts.show', compact('alert'));
}

public function edit(Alert $alert)
{
$users = User::all();
return view('alerts.edit', compact('alert', 'users'));
}
public function update(Request $request, Alert $alert)
{
$request->validate([
'User Id' => 'nullable|exists:users,User Id',
'Message' => 'required|max:256',
'IsRead' => 'boolean',
]);
$alert->update($request->all());
return redirect()->route('alerts.index')->with('success', 'Alert updated successfully.');
}
public function destroy(Alert $alert)
{
$alert->delete();
return redirect()->route('alerts.index')->with('success', 'Alert deleted successfully.');
}
}

9. ReportController


// app/Http/Controllers/ReportController.php
namespace App\Http\Controllers;
use App\Models\Report;
use App\Models\User;
use Illuminate\Http\Request;
class ReportController extends Controller
{
public function index()
{
$reports = Report::with('user')->get();
return view('reports.index', compact('reports'));
}
public function create()
{
$users = User::all();
return view('reports.create', compact('users'));
}
public function store(Request $request)
{
$request->validate([
'User Id' => 'nullable|exists:users,User Id',
'ReportDate' => 'required|date',
'Description' => 'nullable',
]);
Report::create($request->all());
return redirect()->route('reports.index')->with('success', 'Report created successfully.');
}
public function show(Report $report)
{
return view('reports.show', compact('report'));
}
public function edit(Report $report)
{
$users = User::all();
return view('reports.edit', compact('report', 'users'));
}
public function update(Request $request, Report $report)
{
$request->validate([
'User Id' => 'nullable|exists:users,User Id',
'ReportDate' => 'required|date',
'Description' => 'nullable',
]);
$report->update($request->all());
return redirect()->route('reports.index')->with('success', 'Report updated successfully.');
}
public function destroy(Report $report)
{
$report->delete();
return redirect()->route('reports.index')->with('success', 'Report deleted successfully.');
}
}

Step 3: Create Views

For each controller, you will need to create views for the respective operations. The views should be placed in the resources/views directory, organized by model. Here's a basic structure for the views:


resources/views/users/index.blade.php
resources/views/users/create.blade.php
resources/views/users/edit.blade.php
resources/views/users/show.blade.php
resources/views/roles/index.blade.php
resources/views/roles/create.blade.php
resources/views/roles/edit.blade.php
resources/views/roles/show.blade.php
resources/views/traffic_data/index.blade.php
resources/views/traffic_data/create.blade.php
resources/views/traffic_data/edit.blade.php
resources/views/traffic_data/show.blade.php
resources/views/incidents/index.blade.php
resources/views/incidents/create.blade.php
resources/views/incidents/edit.blade.php
resources/views/incidents/show.blade.php
resources/views/signals/index.blade.php
resources/views/signals/create.blade.php
resources/views/signals/edit.blade.php
resources/views/signals/show.blade.php
resources/views/performance_metrics/index.blade.php
resources/views/performance_metrics/create.blade.php
resources/views/performance_metrics/edit.blade.php
resources/views/performance_metrics/show.blade.php
resources/views/routes/index.blade.php
resources/views/routes/create.blade.php
resources/views/routes/edit.blade.php
resources/views/routes/show.blade.php
resources/views/alerts/index.blade.php
resources/views/alerts/create.blade.php
resources/views/alerts/edit.blade.php
resources/views/alerts/show.blade.php
resources/views/reports/index.blade.php
resources/views/reports/create.blade.php
resources/views/reports/edit.blade.php
resources/views/reports/show.blade.php

Below are example view files for each controller, designed using Bootstrap 5.

Each view includes basic CRUD functionality, such as displaying a list of records, creating new records, editing existing records, and showing details of a record.

1. User Views

resources/views/users/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Users</h1>
<a href="{{ route('users.create') }}" class="btn btn-primary mb-3">Create User</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td>{{ $user->Username }}</td>
<td>{{ $user->Email }}</td>
<td>{{ $user->role->RoleName ?? 'N/A' }}</td>
<td>
<a href="{{ route('users.show', $user) }}" class="btn btn-info">View</a>
<a href="{{ route('users.edit', $user) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('users.destroy', $user) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/users/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create User</h1>
<form action="{{ route('users.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="Username" class="form-label">Username</label>
<input type="text" class="form-control" id="Username" name="Username" required>
</div>
<div class="mb-3">
<label for="PasswordHash" class="form-label">Password</label>
<input type="password" class="form-control" id="PasswordHash" name="PasswordHash" required>
</div>
<div class="mb-3">
<label for="Email" class="form-label">Email</label>
<input type="email" class="form-control" id="Email" name="Email" required>
</div>
<div class="mb-3">
<label for="RoleId" class="form-label">Role</label>
<select class="form-select" id="RoleId" name="RoleId">
<option value="">Select Role</option>
@foreach($roles as $role)
<option value="{{ $role->RoleId }}">{{ $role->RoleName }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Create User</button>
</form>
</div>
@endsection

resources/views/users/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit User</h1>
<form action="{{ route('users.update', $user) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="Username" class="form-label">Username</label>
<input type="text" class="form-control" id="Username" name="Username" value="{{ $user->Username }}" required>
</div>
<div class="mb-3">
<label for="PasswordHash" class="form-label">Password</label>
<input type="password" class="form-control" id="PasswordHash" name="PasswordHash" required>
</div>
<div class="mb-3">
<label for="Email" class="form-label">Email</label>
<input type="email" class="form-control" id="Email" name="Email" value="{{ $user->Email }}" required>
</div>
<div class="mb-3">
<label for="RoleId" class="form-label">Role</label>
<select class="form-select" id="RoleId" name="RoleId">
<option value="">Select Role</option>
@foreach($roles as $role)
<option value ="{{ $role->RoleId }}" {{ $role->RoleId == $user->RoleId ? 'selected' : '' }}>{{ $role->RoleName }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-warning">Update User</button>
</form>
</div>
@endsection

resources/views/users/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>User Details</h1>
<p><strong>Username:</strong> {{ $user->Username }}</p>
<p><strong>Email:</strong> {{ $user->Email }}</p>
<p><strong>Role:</strong> {{ $user->role->RoleName ?? 'N/A' }}</p>
<a href="{{ route('users.edit', $user) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('users.index') }}" class="btn btn-secondary">Back to Users</a>
</div>
@endsection

2. Role Views

resources/views/roles/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Roles</h1>
<a href="{{ route('roles.create') }}" class="btn btn-primary mb-3">Create Role</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>Role Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($roles as $role)
<tr>
<td>{{ $role->RoleName }}</td>
<td>
<a href="{{ route('roles.show', $role) }}" class="btn btn-info">View</a>
<a href="{{ route('roles.edit', $role) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('roles.destroy', $role) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/roles/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Role</h1>
<form action="{{ route('roles.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="RoleName" class="form-label">Role Name</label>
<input type="text" class="form-control" id="RoleName" name="RoleName" required>
</div>
<button type="submit" class="btn btn-primary">Create Role</button>
</form>
</div>
@endsection

resources/views/roles/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Role</h1>
<form action="{{ route('roles.update', $role) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="RoleName" class="form-label">Role Name</label>
<input type="text" class="form-control" id="RoleName" name="RoleName" value="{{ $role->RoleName }}" required>
</div>
<button type="submit" class="btn btn-warning">Update Role</button>
</form>
</div>
@endsection

resources/views/roles/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Role Details</h1>
<p><strong>Role Name:</strong> {{ $role->RoleName }}</p>
<a href="{{ route('roles.edit', $role) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('roles.index') }}" class="btn btn-secondary">Back to Roles</a>
</div>
@endsection

3. Traffic Data Views

resources/views/traffic_data/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Traffic Data</h1>
<a href="{{ route('traffic_data.create') }}" class="btn btn-primary mb-3">Add Traffic Data</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>Location</th>
<th>Timestamp</th>
<th>Vehicle Count</th>
<th>Average Speed</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($trafficData as $data)
<tr>
<td>{{ $data->Location }}</td>
<td>{{ $data->Timestamp }}</td>
<td>{{ $data->VehicleCount }}</td>
<td>{{ $data->AverageSpeed }}</td>
<td>
<a href="{{ route('traffic_data.show', $data) }}" class="btn btn-info">View</a>
<a href="{{ route('traffic_data.edit', $data) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('traffic_data.destroy', $data) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/traffic_data/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Add Traffic Data</h1>
<form action="{{ route('traffic_data.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="Location" class="form-label">Location</label>
<input type="text" class="form-control" id="Location" name="Location" required>
</div>
<div class="mb-3">
<label for="Timestamp" class="form-label">Timestamp</label>
<input type="datetime-local" class="form-control" id="Timestamp" name="Timestamp" required>
</div>
<div class="mb-3">
<label for="VehicleCount" class="form-label">Vehicle Count</label>
<input type="number" class="form-control" id="VehicleCount" name="VehicleCount" required>
</div>
<div class="mb-3">
<label for="AverageSpeed" class="form-label">Average Speed</label>
<input type="number" step="0.01" class="form-control" id="AverageSpeed" name="AverageSpeed" required>
</div>
<button type="submit" class="btn btn-primary">Add Traffic Data</button>
</form>
</div>
@endsection

resources/views/traffic_data/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Traffic Data</h1>
<form action="{{ route('traffic_data.update', $trafficData) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="Location" class="form-label">Location</label>
<input type="text" class="form-control" id="Location" name="Location" value="{{ $trafficData->Location }}" required>
</div>
<div class="mb-3">
<label for="Timestamp" class="form-label">Timestamp</label>
<input type="datetime-local" class="form-control" id="Timestamp" name="Timestamp" value="{{ $trafficData->Timestamp }}" required>
</div>
<div class="mb-3">
<label for="VehicleCount" class="form-label">Vehicle Count</label>
<input type="number" class="form-control" id="VehicleCount" name="VehicleCount" value="{{ $trafficData->VehicleCount }}" required>
</div>
<div class="mb-3">
<label for="AverageSpeed" class="form-label">Average Speed</label>
<input type="number" step="0.01" class="form-control" id="AverageSpeed" name="AverageSpeed" value="{{ $trafficData->AverageSpeed }}" required>
</div>
<button type="submit" class="btn btn-warning">Update Traffic Data</button>
</form>
</div>
@endsection

resources/views/traffic_data/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Traffic Data Details</h1>
<p><strong>Location:</strong> {{ $trafficData->Location }}</p>
<p><strong>Timestamp:</strong> {{ $trafficData ->Timestamp }}</p>
<p><strong>Vehicle Count:</strong> {{ $trafficData->VehicleCount }}</p>
<p><strong>Average Speed:</strong> {{ $trafficData->AverageSpeed }}</p>
<a href="{{ route('traffic_data.edit', $trafficData) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('traffic_data.index') }}" class="btn btn-secondary">Back to Traffic Data</a>
</div>
@endsection

4. Incident Views

resources/views/incidents/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Incidents</h1>
<a href="{{ route('incidents.create') }}" class="btn btn-primary mb-3">Report Incident</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>Description</th>
<th>Location</th>
<th>Severity</th>
<th>Timestamp</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($incidents as $incident)
<tr>
<td>{{ $incident->Description }}</td>
<td>{{ $incident->Location }}</td>
<td>{{ $incident->Severity }}</td>
<td>{{ $incident->Timestamp }}</td>
<td>
<a href="{{ route('incidents.show', $incident) }}" class="btn btn-info">View</a>
<a href="{{ route('incidents.edit', $incident) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('incidents.destroy', $incident) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/incidents/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Report Incident</h1>
<form action="{{ route('incidents.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="Description" class="form-label">Description</label>
<textarea class="form-control" id="Description" name="Description" required></textarea>
</div>
<div class="mb-3">
<label for="Location" class="form-label">Location</label>
<input type="text" class="form-control" id="Location" name="Location" required>
</div>
<div class="mb-3">
<label for="Severity" class="form-label">Severity</label>
<input type="text" class="form-control" id="Severity" name="Severity" required>
</div>
<div class="mb-3">
<label for="Timestamp" class="form-label">Timestamp</label>
<input type="datetime-local" class="form-control" id="Timestamp" name="Timestamp" required>
</div>
<button type="submit" class="btn btn-primary">Report Incident</button>
</form>
</div>
@endsection

resources/views/incidents/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Incident</h1>
<form action="{{ route('incidents.update', $incident) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="Description" class="form-label">Description</label>
<textarea class="form-control" id="Description" name="Description" required>{{ $incident->Description }}</textarea>
</div>
<div class="mb-3">
<label for="Location" class="form-label">Location</label>
<input type="text" class="form-control" id="Location" name="Location" value="{{ $incident->Location }}" required>
</div>
<div class="mb-3">
<label for="Severity" class="form-label">Severity</label>
<input type="text" class="form-control" id="Severity" name="Severity" value="{{ $incident->Severity }}" required>
</div>
<div class="mb-3">
<label for="Timestamp" class="form-label">Timestamp</label>
<input type="datetime-local" class="form-control" id="Timestamp" name="Timestamp" value="{{ $incident->Timestamp }}" required>
</div>
<button type="submit" class="btn btn-warning">Update Incident</button>
</form>
</div>
@endsection

resources/views/incidents/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Incident Details</h1>
<p><strong>Description:</strong> {{ $incident->Description }}</p>
<p><strong>Location:</strong> {{ $incident->Location }}</p>
<p><strong>Severity:</strong> {{ $incident->Severity }}</p>
<p><strong>Timestamp:</strong> {{ $incident->Timestamp }}</p>
<a href="{{ route('incidents.edit', $incident) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('incidents.index') }}" class="btn btn-secondary">Back to Incidents</a>
</div>
@endsection

5. Signal Views

resources/views/signals/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Signals</h1>
<a href="{{ route('signals.create') }}" class="btn btn-primary mb-3">Add Signal</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>Location</th>
<th>Signal Type</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($signals as $signal)
<tr>
<td>{{ $signal->Location }}</td>
<td>{{ $signal->SignalType }}</td>
<td>{{ $signal->Status }}</td>
<td>
<a href="{{ route('signals.show', $signal) }}" class="btn btn-info">View</a>
<a href="{{ route('signals.edit', $signal) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('signals.destroy', $signal) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/signals/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Add Signal</h1>
<form action="{{ route('signals.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="Location" class="form-label">Location</label>
<input type="text" class="form-control" id="Location" name="Location" required>
</div>
<div class="mb-3">
<label for="SignalType" class="form-label">Signal Type</label>
<input type="text" class="form-control" id="SignalType" name="SignalType" required>
</div>
<div class="mb-3">
<label for="Status" class="form-label">Status</label>
<input type="text" class="form-control" id="Status" name="Status" required>
</div>
<button type="submit" class="btn btn-primary">Add Signal</button>
</form>
</div>
@endsection

resources/views/signals/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Signal</h1>
<form action="{{ route('signals.update', $signal) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="Location" class="form-label">Location</label>
<input type="text" class="form-control" id="Location" name="Location" value="{{ $signal->Location }}" required>
</div>
<div class="mb-3">
<label for="SignalType" class="form-label">Signal Type</label>
<input type="text" class="form-control" id="SignalType" name="SignalType" value="{{ $signal->SignalType }}" required>
</div>
<div class="mb-3">
<label for="Status" class="form-label">Status</label>
<input type="text" class="form-control" id="Status" name="Status" value="{{ $signal->Status }}" required>
</div>
<button type="submit" class="btn btn-warning">Update Signal</button>
</form>
</div>
@endsection

resources/views/signals/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Signal Details</h1>
<p><strong>Location:</strong> {{ $signal->Location }}</p>
<p><strong>Signal Type:</strong> {{ $signal->SignalType }}</p>
<p><strong>Status:</strong> {{ $signal->Status }}</p>
<a href="{{ route('signals.edit', $signal) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('signals.index') }}" class="btn btn-secondary">Back to Signals</a>
</div>
@endsection

6. Performance Metric Views

resources/views/performance_metrics/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Performance Metrics</h1>
<a href="{{ route('performance_metrics.create') }}" class="btn btn-primary mb-3">Add Metric</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>Metric Name</th>
<th>Value</th>
<th>Timestamp</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($metrics as $metric)
<tr>
<td>{{ $metric->MetricName }}</td>
<td>{{ $metric->Value }}</td>
<td>{{ $metric->Timestamp }}</td>
<td>
<a href="{{ route('performance_metrics.show', $metric) }}" class="btn btn-info">View</a>
<a href="{{ route('performance_metrics.edit', $metric) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('performance_metrics.destroy', $metric) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/performance_metrics/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Add Performance Metric</h1>
<form action="{{ route('performance_metrics.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="MetricName" class="form-label">Metric Name</label>
<input type="text" class="form-control" id="MetricName" name="MetricName" required>
</div>
<div class="mb-3">
<label for="Value" class="form-label">Value</label>
<input type="number" step="0.01" class="form-control" id="Value" name="Value" required>
</div>
<div class="mb-3">
<label for="Timestamp" class="form-label">Timestamp</label>
<input type="datetime-local" class="form-control" id="Timestamp" name="Timestamp" required>
</div>
<button type="submit" class="btn btn-primary">Add Metric</button>
</form>
</div>
@endsection

resources/views/performance_metrics/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Performance Metric</h1>
<form action="{{ route('performance_metrics.update', $metric) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="MetricName" class="form-label">Metric Name</label>
<input type="text" class="form-control" id="MetricName" name="MetricName" value="{{ $metric->MetricName }}" required>
</div>
<div class="mb-3">
<label for="Value" class="form-label">Value</label>
<input type="number" step="0.01" class="form-control" id="Value" name="Value" value="{{ $metric->Value }}" required>
</div>
<div class="mb-3">
<label for="Timestamp" class="form-label">Timestamp</label>
<input type="datetime-local" class="form-control" id="Timestamp" name="Timestamp" value="{{ $metric->Timestamp }}" required>
</div>
<button type="submit" class="btn btn-warning">Update Metric</button>
</form>
</div>
@endsection

resources/views/performance_metrics/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Performance Metric Details</h1>
<p><strong>Metric Name:</strong> {{ $metric->MetricName }}</p>
<p><strong>Value:</strong> {{ $metric->Value }}</p>
<p><strong>Timestamp:</strong> {{ $metric->Timestamp }}</p>
<a href="{{ route('performance_metrics.edit', $metric) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('performance_metrics.index') }}" class="btn btn-secondary">Back to Metrics</a>
</div>
@endsection

7. Route Views

resources/views/routes/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Routes</h1>
<a href="{{ route('routes.create') }}" class="btn btn-primary mb-3">Add Route</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>Start Location</th>
<th>End Location</th>
<th>Distance</th>
<th>Estimated Time</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($routes as $route)
<tr>
<td>{{ $route->StartLocation }}</td>
<td>{{ $route->EndLocation }}</td>
<td>{{ $route->Distance }}</td>
<td>{{ $route->EstimatedTime }}</td>
<td>
<a href="{{ route('routes.show', $route) }}" class="btn btn-info">View</a>
<a href="{{ route('routes.edit', $route) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('routes.destroy', $route) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/routes/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Add Route</h1>
<form action="{{ route('routes.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="StartLocation" class="form-label">Start Location</label>
<input type="text" class="form-control" id="StartLocation" name="StartLocation" required>
</div>
<div class="mb-3">
<label for="EndLocation" class="form-label">End Location</label>
<input type="text" class="form-control" id="EndLocation" name="EndLocation" required>
</div>
<div class="mb-3">
<label for="Distance" class="form-label">Distance</label>
<input type="number" class="form-control" id="Distance" name="Distance" required>
</div>
<div class="mb-3">
<label for="EstimatedTime" class="form-label">Estimated Time</label>
<input type="number" class="form-control" id="EstimatedTime" name="EstimatedTime" required>
</div>
<button type="submit" class="btn btn-primary">Add Route</button>
</form>
</div>
@endsection

resources/views/routes/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Route</h1>
<form action="{{ route('routes.update', $route) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="StartLocation" class="form-label">Start Location</label>
<input type="text" class="form-control" id="StartLocation" name="StartLocation" value="{{ $route->StartLocation }}" required>
</div>
<div class="mb-3">
<label for="EndLocation" class="form-label">End Location</label>
<input type="text" class="form-control" id="EndLocation" name="EndLocation" value="{{ $route->EndLocation }}" required>
</div>
<div class="mb-3">
<label for="Distance" class="form-label">Distance</label>
<input type="number" class="form-control" id="Distance" name="Distance" value="{{ $route->Distance }}" required>
</div>
<div class="mb-3">
<label for="EstimatedTime" class="form-label">Estimated Time</label>
<input type="number" class="form-control" id="EstimatedTime" name="EstimatedTime" value="{{ $route->EstimatedTime }}" required>
</div>
<button type="submit" class="btn btn-warning">Update Route</button>
</form>
</div>
@endsection

resources/views/routes/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Route Details</h1>
<p><strong>Start Location:</strong> {{ $route->StartLocation }}</p>
<p><strong>End Location:</strong> {{ $route->EndLocation }}</p>
<p><strong>Distance:</strong> {{ $route->Distance }}</p>
<p><strong>Estimated Time:</strong> {{ $route->EstimatedTime }}</p>
<a href="{{ route('routes.edit', $route) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('routes.index') }}" class="btn btn-secondary">Back to Routes</a>
</div>
@endsection

8. Alert Views

resources/views/alerts/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Alerts</h1>
<a href="{{ route('alerts.create') }}" class="btn btn-primary mb-3">Create Alert</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>User</th>
<th>Message</th>
<th>Is Read</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($alerts as $alert)
<tr>
<td>{{ $alert->user->Username ?? 'N/A' }}</td>
<td>{{ $alert->Message }}</td>
<td>{{ $alert->IsRead ? 'Yes' : 'No' }}</td>
<td>
<a href="{{ route('alerts.show', $alert) }}" class="btn btn-info">View</a>
<a href="{{ route('alerts.edit', $alert) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('alerts.destroy', $alert) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/alerts/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Alert</h1>
<form action="{{ route('alerts.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id">
<option value="">Select User</option>
@foreach($users as $user)
<option value="{{ $user->User Id }}">{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Message" class="form-label">Message</label>
<textarea class="form-control" id="Message" name="Message" required></textarea>
</div>
<div class="mb-3">
<label for="IsRead" class="form-label">Is Read</label>
<select class="form-select" id="IsRead" name="IsRead">
<option value="0">No</option>
<option value="1">Yes</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Create Alert</button>
</form>
</div>
@endsection

resources/views/alerts/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Alert</h1>
<form action="{{ route('alerts.update', $alert) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id">
<option value="">Select User</option>
@foreach($users as $user)
<option value="{{ $user->User Id }}" {{ $user->User Id == $alert->User Id ? 'selected' : '' }}>{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Message" class="form-label">Message</label>
<textarea class="form-control" id="Message" name="Message" required>{{ $alert->Message }}</textarea>
</div>
<div class="mb-3">
<label for="IsRead" class="form-label">Is Read</label>
<select class="form-select" id="IsRead" name="IsRead">
<option value="0" {{ $alert->IsRead ? '' : 'selected' }}>No</option>
<option value="1" {{ $alert->IsRead ? 'selected' : '' }}>Yes</option>
</select>
</div>
<button type="submit" class="btn btn-warning">Update Alert</button>
</form>
</div>
@endsection

resources/views/alerts/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Alert Details</h1>
<p><strong>User:</strong> {{ $alert->user->Username ?? 'N/A' }}</p>
<p><strong>Message:</strong> {{ $alert->Message }}</p>
<p><strong>Is Read:</strong> {{ $alert->IsRead ? 'Yes' : 'No' }}</p>
<a href="{{ route('alerts.edit', $alert) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('alerts.index') }}" class="btn btn-secondary">Back to Alerts</a>
</div>
@endsection

9. Report Views

resources/views/reports/index.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Reports</h1>
<a href="{{ route('reports.create') }}" class="btn btn-primary mb-3">Create Report</a>
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
<table class="table">
<thead>
<tr>
<th>User</th>
<th>Report Date</th>
<th>Description</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach($reports as $report)
<tr>
<td>{{ $report->user->Username ?? 'N/A' }}</td>
<td>{{ $report->ReportDate }}</td>
<td>{{ $report->Description }}</td>
<td>
<a href="{{ route('reports.show', $report) }}" class="btn btn-info">View</a>
<a href="{{ route('reports.edit', $report) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('reports.destroy', $report) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

resources/views/reports/create.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Report</h1>
<form action="{{ route('reports.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id">
<option value="">Select User</option>
@foreach($users as $user)
<option value="{{ $user->User Id }}">{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="ReportDate" class="form-label">Report Date</label>
<input type="date" class="form-control" id="ReportDate" name="ReportDate" required>
</div>
<div class="mb-3">
<label for="Description" class="form-label">Description</label>
<textarea class="form-control" id="Description" name="Description"></textarea>
</div>
<button type="submit" class="btn btn-primary">Create Report</button>
</form>
</div>
@endsection

resources/views/reports/edit.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Report</h1>
<form action="{{ route('reports.update', $report) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="User Id" class="form-label">User </label>
<select class="form-select" id="User Id" name="User Id">
<option value="">Select User</option>
@foreach($users as $user)
<option value="{{ $user->User Id }}" {{ $user->User Id == $report->User Id ? 'selected' : '' }}>{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="ReportDate" class="form-label">Report Date</label>
<input type="date" class="form-control" id="ReportDate" name="ReportDate" value="{{ $report->ReportDate }}" required>
</div>
<div class="mb-3">
<label for="Description" class="form-label">Description</label>
<textarea class="form-control" id="Description" name="Description">{{ $report->Description }}</textarea>
</div>
<button type="submit" class="btn btn-warning">Update Report</button>
</form>
</div>
@endsection

resources/views/reports/show.blade.php


@extends('layouts.app')
@section('content')
<div class="container">
<h1>Report Details</h1>
<p><strong>User:</strong> {{ $report->user->Username ?? 'N/A' }}</p>
<p><strong>Report Date:</strong> {{ $report->ReportDate }}</p>
<p><strong>Description:</strong> {{ $report->Description }}</p>
<a href="{{ route('reports.edit', $report) }}" class="btn btn-warning">Edit</a>
<a href="{{ route('reports.index') }}" class="btn btn-secondary">Back to Reports</a>
</div>
@endsection

This completes the view files for all controllers, utilizing Bootstrap 5 for styling and layout.

Each view is structured to facilitate CRUD operations effectively.

To create a layout view file in Laravel that can be used across your application, you typically create a file named app.blade.php (or similar) in the resources/views/layouts directory.

This layout will include the common HTML structure, Bootstrap 5 CSS, and any necessary JavaScript files.

Here's an example of a basic layout file using Bootstrap 5:

resources/views/layouts/app.blade.php


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@yield('title', 'My Application')</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="{{ asset('css/app.css') }}"> <!-- Optional custom CSS -->
@yield('styles') <!-- For additional styles -->
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="{{ url('/') }}">My Application</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="{{ route('users.index') }}">Users</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('roles.index') }}">Roles</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('traffic_data.index') }}">Traffic Data</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('incidents.index') }}">Incidents</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('signals.index') }}">Signals</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('performance_metrics.index') }}">Performance Metrics</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('routes.index') }}">Routes</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('alerts.index') }}">Alerts</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('reports.index') }}">Reports</a>
</li>
</ul>
</div>
</div>
</nav>

<div class="container mt-4">
@yield('content')
</div>

<footer class="bg-light text-center text-lg-start mt-4">
<div class="text-center p-3">
© 2023 My Application
</div>
</footer>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
@yield('scripts') <!-- For additional scripts -->
</body>
</html>

To use this layout in your views, you can extend it like this:


@extends('layouts.app')
@section('title', 'User Management')
@section('content')
<!-- Your content here -->
@endsection

To create a dashboard page in Laravel for displaying consolidated project data, you should start by setting up a route and a controller method that fetches the necessary data from your models.

Then, create a view that utilizes a layout file to present the data in a user-friendly format. Consider using libraries like Chart.js for visualizations and ensure your dashboard is responsive and intuitive.

Step 1: Define the Route

In your routes/web.php, add a route for the dashboard:


Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

Step 2: Create the Dashboard Controller

Generate a controller if you haven't already:


php artisan make:controller DashboardController

Then, in app/Http/Controllers/DashboardController.php, implement the index method to fetch the consolidated data:


namespace App\Http\Controllers;
use App\Models\Project; // Assuming you have a Project model
use Illuminate\Http\Request;

class DashboardController extends Controller
{
public function index()
{
$projects = Project::all(); // Fetch all projects
$totalProjects = $projects->count();
$completedProjects = $projects->where('status', 'completed')->count();
$pendingProjects = $projects->where('status', 'pending')->count();

return view('dashboard.index', compact('totalProjects', 'completedProjects', 'pendingProjects'));
}
}

Step 3: Create the Dashboard View

Create a new view file at resources/views/dashboard/index.blade.php:


@extends('layouts.app')
@section('title', 'Dashboard')
@section('content')
<div class="container">
<h1 class="mb-4">Dashboard</h1>
<div class="row">
<div class="col-md-4">
<div class="card text-white bg-success mb-3">
<div class="card-header">Total Projects</div>
<div class="card-body">
<h5 class="card-title">{{ $totalProjects }}</h5>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-white bg-info mb-3">
<div class="card-header">Completed Projects</div>
<div class="card-body">
<h5 class="card-title">{{ $completedProjects }}</h5>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card text-white bg-warning mb-3">
<div class="card-header">Pending Projects</div>
<div class="card-body">
<h5 class="card-title">{{ $pendingProjects }}</h5>
</div>
</div>
</div>
</div>
<!-- Additional sections for charts or detailed data can be added here -->
</div>
@endsection

Explanation of the Dashboard View

Card Layout: The dashboard uses Bootstrap cards to display the total number of projects, completed projects, and pending projects.

Dynamic Data: The data displayed in the cards is dynamically fetched from the controller and passed to the view.

Responsive Design: The layout is responsive, ensuring it looks good on various screen sizes.

Step 4: Access the Dashboard

You can now access your dashboard by navigating to /dashboard in your web browser. This will display the consolidated data related to your projects in a user-friendly format.

Optional: Adding Charts

For a more interactive dashboard, consider integrating Chart.js or another charting library to visualize project data trends over time. You can include the necessary scripts in your layout and create a dedicated section in your dashboard view for charts.