Project Introduction

The Search Engine Project is an innovative web-based application designed to facilitate the retrieval of information from the vast resources available on the internet. This system aims to provide users with a powerful tool to search for relevant content quickly and efficiently, utilizing advanced algorithms and indexing techniques. With the exponential growth of online data, the need for an effective search engine has become essential for users seeking accurate and timely information.

The platform features a user-friendly interface that allows users to enter search queries and receive a list of relevant results in real-time. The search engine employs sophisticated ranking algorithms to ensure that the most pertinent results are displayed at the top. Additionally, the system includes features such as advanced search options, filters, and suggestions to enhance the user experience. By automating the search process, the Search Engine Project aims to improve information accessibility and empower users to find what they need with ease.

Project Objectives

  • To develop an intuitive interface for users to perform searches effortlessly.
  • To implement advanced indexing techniques to efficiently organize and retrieve data.
  • To utilize ranking algorithms to ensure the most relevant results are displayed first.
  • To provide advanced search options and filters to refine search results.
  • To enable users to save and bookmark their favorite searches and results.
  • To generate analytics on search trends and user behavior for continuous improvement.
  • To ensure data security and privacy for all user search queries and interactions.
  • To enhance user engagement through personalized search suggestions and trending topics.

Project Modules

Web Crawling Module

  • Web Crawler: Develop a web crawler (or spider) that systematically browses the web to discover and index new web pages.
  • URL Management: Maintain a queue of URLs to be crawled, including mechanisms to avoid duplicates and manage crawl depth.
  • Robots.txt Compliance: Ensure the crawler respects the rules specified in the robots.txt file of websites.

Data Indexing Module

  • Content Extraction: Extract relevant content from crawled web pages, including text, images, and metadata (e.g., title, description).
  • Index Creation: Create an inverted index that maps keywords to their locations in the documents, allowing for efficient retrieval.
  • Data Storage: Store indexed data in a database or search engine-specific data structure for quick access.

Query Processing Module

  • Query Parsing: Analyze and parse user queries to understand the intent and structure (e.g., handling Boolean operators, phrases).
  • Synonym Handling: Implement synonym recognition to improve search relevance (e.g., recognizing "car" and "automobile" as similar).
  • Spell Correction: Provide suggestions for misspelled words in user queries.

Ranking Algorithm Module

  • Relevance Scoring: Develop algorithms to score and rank search results based on relevance to the user’s query (e.g., TF-IDF, BM25).
  • PageRank: Implement link analysis algorithms like PageRank to evaluate the importance of web pages based on their link structure.
  • Personalization: Incorporate user behavior and preferences to personalize search results.

Search Interface Module

  • User Interface (UI): Design a user-friendly search interface that allows users to enter queries and view results.
  • Result Display: Present search results in an organized manner, including titles, snippets, URLs, and relevant metadata.
  • Faceted Search: Provide filtering options to help users refine their search results based on categories, date, or other attributes.

Caching Module

  • Result Caching: Implement caching mechanisms to store frequently accessed search results for faster retrieval.
  • Content Caching: Cache web pages or content to reduce the need for repeated crawling and indexing.

Analytics and Reporting Module

  • User Analytics: Track user interactions, including search queries, click-through rates, and session durations.
  • Performance Metrics: Measure the performance of the search engine, including response times and accuracy of results.
  • Reporting Tools: Generate reports on search trends, popular queries, and user behavior.

Feedback and Improvement Module

  • User Feedback Collection: Allow users to provide feedback on search results (e.g., helpful, not helpful).
  • Continuous Learning: Implement machine learning techniques to improve search algorithms based on user feedback and behavior.

Security and Access Control Module

  • Data Security: Ensure that user data and search queries are stored securely and comply with privacy regulations.
  • Access Control: Manage access to different features of the search engine based on user roles (e.g., admin, user).

Project Tables Queries


-- Users Table
CREATE TABLE Users (
UserId INT PRIMARY KEY IDENTITY(1,1),
Username NVARCHAR(50) NOT NULL UNIQUE,
PasswordHash NVARCHAR(255) NOT NULL,
Email NVARCHAR(100) NOT NULL UNIQUE,
CreatedAt DATETIME DEFAULT GETDATE(),
UpdatedAt DATETIME DEFAULT GETDATE(),
RoleId INT,
FOREIGN KEY (RoleId) REFERENCES Roles(RoleId)
);
-- Roles Table
CREATE TABLE Roles (
RoleId INT PRIMARY KEY IDENTITY(1,1),
RoleName NVARCHAR(50) NOT NULL UNIQUE
);
-- URLs Table
CREATE TABLE URLs (
URLId INT PRIMARY KEY IDENTITY(1,1),
URL NVARCHAR(255) NOT NULL UNIQUE,
Status NVARCHAR(20) DEFAULT 'Pending', -- e.g., Pending, Crawled, Error
LastCrawled DATETIME,
CreatedAt DATETIME DEFAULT GETDATE(),
UpdatedAt DATETIME DEFAULT GETDATE()
);
-- IndexedPages Table
CREATE TABLE IndexedPages (
PageId INT PRIMARY KEY IDENTITY(1,1),
URLId INT,
Title NVARCHAR(255),
Content NVARCHAR(MAX),
MetaDescription NVARCHAR(255),
CreatedAt DATETIME DEFAULT GETDATE(),
UpdatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (URLId) REFERENCES URLs(URLId)
);
-- Queries Table
CREATE TABLE Queries (
QueryId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
SearchTerm NVARCHAR(255) NOT NULL,
SearchDate DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);
-- SearchResults Table
CREATE TABLE SearchResults (
ResultId INT PRIMARY KEY IDENTITY(1,1),
QueryId INT,
PageId INT,
Rank INT,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (QueryId) REFERENCES Queries(QueryId),
FOREIGN KEY (PageId) REFERENCES IndexedPages(PageId)
);
-- CacheItems Table
CREATE TABLE CacheItems (
CacheItemId INT PRIMARY KEY IDENTITY(1,1),
Key NVARCHAR(255) NOT NULL UNIQUE,
Value NVARCHAR(MAX),
Expiration DATETIME,
CreatedAt DATETIME DEFAULT GETDATE(),
UpdatedAt DATETIME DEFAULT GETDATE()
);
-- AnalyticsData Table
CREATE TABLE AnalyticsData (
AnalyticsId INT PRIMARY KEY IDENTITY(1,1),
QueryId INT,
Clicks INT DEFAULT 0,
Impressions INT DEFAULT 0,
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (QueryId) REFERENCES Queries(QueryId)
);
-- Feedback Table
CREATE TABLE Feedbacks (
FeedbackId INT PRIMARY KEY IDENTITY(1,1),
UserId INT,
Comments NVARCHAR(MAX),
Rating INT CHECK (Rating >= 1 AND Rating <= 5),
CreatedAt DATETIME DEFAULT GETDATE(),
FOREIGN KEY (User Id) REFERENCES Users(UserId)
);
-- SecuritySettings Table
CREATE TABLE SecuritySettings (
SettingId INT PRIMARY KEY IDENTITY(1,1),
SettingName NVARCHAR(100) NOT NULL UNIQUE,
SettingValue NVARCHAR(255),
CreatedAt DATETIME DEFAULT GETDATE(),
UpdatedAt DATETIME DEFAULT GETDATE()
);

Explanation of Tables

Users: Stores user information, including credentials and roles.

Roles: Defines different roles within the system (e.g., admin, user).

URLs: Manages the URLs that the crawler will process, including their status and last crawled date.

IndexedPages: Contains the pages that have been indexed, including their content and metadata.

Queries: Records search queries made by users, along with the search date.

SearchResults: Stores the results of search queries, linking them to the indexed pages and their rank.

CacheItems: Manages cached items for quick retrieval of frequently accessed data.

AnalyticsData: Tracks analytics related to search queries, such as clicks and impressions.

Feedback: Collects feedback from users regarding their search experience.

SecuritySettings: Stores security-related settings for the application.

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

Below, I will provide the migration files and the corresponding Eloquent models for each table.

Step 1: Create Migrations

You can create migrations using the Artisan command. For example, to create a migration for the users table, you would run:


php artisan make:migration create_users_table

Repeat this for each table. Below are the migration files for each table based on your SQL schema.

Migration for Users Table


// database/migrations/2025_02_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', 255);
$table->string('Email', 100)->unique();
$table->timestamps();
$table->foreignId('RoleId')->nullable()->constrained('roles', 'RoleId');
});
}
public function down()
{
Schema::dropIfExists('users');
}
}

Migration for Roles Table


// database/migrations/2025_02_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();
});
}
public function down()
{
Schema::dropIfExists('roles');
}
}

Migration for URLs Table


// database/migrations/2025_02_01_000003_create_urls_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUrlsTable extends Migration
{
public function up()
{
Schema::create('urls', function (Blueprint $table) {
$table->id('URLId');
$table->string('URL', 255)->unique();
$table->string('Status', 20)->default('Pending');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('urls');
}
}

Migration for IndexedPages Table


// database/migrations/2025_02_01_000004_create_indexed_pages_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateIndexedPagesTable extends Migration
{
public function up()
{
Schema::create('indexed_pages', function (Blueprint $table) {
$table->id('PageId');
$table->foreignId('URLId')->constrained('urls', 'URLId');
$table->string('Title', 255)->nullable();
$table->text('Content')->nullable();
$table->string('MetaDescription', 255)->nullable();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('indexed_pages');
}
}

Migration for Queries Table


// database/migrations/2025_02_01_000005_create_queries_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateQueriesTable extends Migration
{
public function up()
{
Schema::create('queries', function (Blueprint $table) {
$table->id('QueryId');
$table->foreignId('User Id')->constrained('users', 'User Id');
$table->string('SearchTerm', 255);
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('queries');
}
}

Migration for SearchResults Table


// database/migrations/2025_02_01_000006_create_search_results_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSearchResultsTable extends Migration
{
public function up()
{
Schema::create('search_results', function (Blueprint $table) {
$table->id('ResultId');
$table->foreignId('QueryId')->constrained('queries', 'QueryId');
$table->foreignId('PageId')->constrained('indexed_pages', 'PageId');
$table->integer('Rank')->nullable();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('search _results');
}
}

Migration for CacheItems Table


// database/migrations/2025_02_01_000007_create_cache_items_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCacheItemsTable extends Migration
{
public function up()
{
Schema::create('cache_items', function (Blueprint $table) {
$table->id('CacheItemId');
$table->string('Key', 255)->unique();
$table->text('Value')->nullable();
$table->dateTime('Expiration')->nullable();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('cache_items');
}
}

Migration for AnalyticsData Table


// database/migrations/2025_02_01_000008_create_analytics_data_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAnalyticsDataTable extends Migration
{
public function up()
{
Schema::create('analytics_data', function (Blueprint $table) {
$table->id('AnalyticsId');
$table->foreignId('QueryId')->constrained('queries', 'QueryId');
$table->integer('Clicks')->default(0);
$table->integer('Impressions')->default(0);
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('analytics_data');
}
}

Migration for Feedback Table


// database/migrations/2025_02_01_000009_create_feedbacks_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFeedbacksTable extends Migration
{
public function up()
{
Schema::create('feedbacks', function (Blueprint $table) {
$table->id('FeedbackId');
$table->foreignId('User Id')->constrained('users', 'User Id');
$table->text('Comments')->nullable();
$table->integer('Rating')->check('Rating >= 1 AND Rating <= 5');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('feedbacks');
}
}

Migration for SecuritySettings Table


// database/migrations/2025_02_01_000010_create_security_settings_table.php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSecuritySettingsTable extends Migration
{
public function up()
{
Schema::create('security_settings', function (Blueprint $table) {
$table->id('SettingId');
$table->string('SettingName', 100)->unique();
$table->string('SettingValue', 255)->nullable();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('security_settings');
}
}

Step 2: Create Eloquent Models

You can create models using the Artisan command. For example, to create a model for the User, you would run:


php artisan make:model User

Repeat this for each table. Below are the Eloquent models for each table.

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 queries()
{
return $this->hasMany(Query::class, 'User Id');
}
public function feedbacks()
{
return $this->hasMany(Feedback::class, 'User Id');
}
}

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',
];
public function users()
{
return $this->hasMany(User::class, 'RoleId');
}
}

URL Model


// app/Models/URL.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class URL extends Model
{
use HasFactory;
protected $table = 'urls';
protected $fillable = [
'URL',
'Status',
];
public function indexedPages()
{
return $this-> hasMany(IndexedPage::class, 'URLId');
}
}

IndexedPage Model


// app/Models/IndexedPage.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class IndexedPage extends Model
{
use HasFactory;
protected $table = 'indexed_pages';
protected $fillable = [
'URLId',
'Title',
'Content',
'MetaDescription',
];
public function url()
{
return $this->belongsTo(URL::class, 'URLId');
}
public function searchResults()
{
return $this->hasMany(SearchResult::class, 'PageId');
}
}

Query Model


// app/Models/Query.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Query extends Model
{
use HasFactory;
protected $table = 'queries';
protected $fillable = [
'User Id',
'SearchTerm',
];
public function user()
{
return $this->belongsTo(User::class, 'User Id');
}
public function searchResults()
{
return $this->hasMany(SearchResult::class, 'QueryId');
}
public function analyticsData()
{
return $this->hasOne(AnalyticsData::class, 'QueryId');
}
}

SearchResult Model


// app/Models/SearchResult.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class SearchResult extends Model
{
use HasFactory;
protected $table = 'search_results';
protected $fillable = [
'QueryId',
'PageId',
'Rank',
];
public function query()
{
return $this->belongsTo(Query::class, 'QueryId');
}
public function indexedPage()
{
return $this->belongsTo(IndexedPage::class, 'PageId');
}
}

CacheItem Model


// app/Models/CacheItem.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class CacheItem extends Model
{
use HasFactory;
protected $table = 'cache_items';
protected $fillable = [
'Key',
'Value',
'Expiration',
];
}

AnalyticsData Model


// app/Models/AnalyticsData.php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class AnalyticsData extends Model
{
use HasFactory;
protected $table = 'analytics_data';
protected $fillable = [
'QueryId',
'Clicks',
'Impressions',
];
public function query()
{
return $this->belongsTo(Query::class, 'QueryId');
}
}

Feedback Model


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

SecuritySetting Model


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

With these migrations and models, you can now manage your database schema and interact with your data using Eloquent in Laravel 11.
To create controllers for each model with complete CRUD operations in Laravel, you can use the Artisan command to generate the controllers. Below, I will provide the commands to create the controllers and the basic structure for each controller, including methods for creating, reading, updating, and deleting records.
Step 1: Create Controllers
You can create 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 URLController --resource
php artisan make:controller IndexedPageController --resource
php artisan make:controller QueryController --resource
php artisan make:controller SearchResultController --resource
php artisan make:controller CacheItemController --resource
php artisan make:controller AnalyticsDataController --resource
php artisan make:controller FeedbackController --resource
php artisan make:controller SecuritySettingController --resource

Step 2: Implement CRUD Operations

Below are the basic implementations for each controller. You can expand these methods as needed.

UserController


// app/Http/Controllers/UserController.php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function index()
{
$users = User::all();
return view('users.index', compact('users'));
}
public function create()
{
return view('users.create');
}
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)
{
return view('users.edit', compact('user'));
}
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.');
}
}

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.');
}
}

URLController


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

IndexedPageController


// app/Http/Controllers/IndexedPageController.php
namespace App\Http\Controllers;
use App\Models\IndexedPage;
use App\Models\URL;
use Illuminate\Http\Request;
class IndexedPageController extends Controller
{
public function index()
{
$indexedPages = IndexedPage::all();
return view('indexed_pages.index', compact('indexedPages'));
}
public function create()
{
$urls = URL::all();
return view('indexed_pages.create', compact('urls'));
}
public function store(Request $request)
{
$request->validate([
'URLId' => 'required|exists:urls,URLId',
'Title' => 'nullable|max:255',
'Content' => 'nullable',
'MetaDescription' => 'nullable|max:255',
]);
IndexedPage::create($request->all());
return redirect()->route('indexed_pages.index')->with('success', 'Indexed Page created successfully.');
}
public function show(IndexedPage $indexedPage)
{
return view('indexed_pages.show', compact('indexedPage'));
}
public function edit(IndexedPage $indexedPage)
{
$urls = URL::all();
return view('indexed_pages.edit', compact('indexedPage', 'urls'));
}
public function update(Request $request, IndexedPage $indexedPage)
{
$request->validate([
'URLId' => 'required|exists:urls,URLId',
'Title' => 'nullable|max:255',
'Content' => 'nullable',
'MetaDescription' => 'nullable|max:255',
]);
$indexedPage->update($request->all());
return redirect()->route('indexed_pages.index')->with('success', 'Indexed Page updated successfully.');
}
public function destroy(IndexedPage $indexedPage)
{
$indexedPage->delete();
return redirect()->route('indexed_pages.index')->with('success', 'Indexed Page deleted successfully.');
}
}

QueryController


// app/Http/Controllers/QueryController.php
namespace App\Http\Controllers;
use App\Models\Query;
use App\Models\User;
use Illuminate\Http\Request;
class QueryController extends Controller
{
public function index()
{
$queries = Query::all();
return view('queries.index', compact('queries'));
}
public function create()
{
$users = User::all();
return view('queries.create', compact('users'));
}
public function store(Request $request)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'SearchTerm' => 'required|max:255',
]);
Query::create($request->all());
return redirect()->route('queries.index')->with('success', 'Query created successfully.');
}
public function show(Query $query)
{
return view('queries.show', compact('query'));
}
public function edit(Query $query)
{
$users = User::all();
return view('queries.edit', compact('query', 'users'));
}
public function update(Request $request, Query $query)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'SearchTerm' => 'required|max:255',
]);
$query->update($request->all());
return redirect()->route('queries.index')->with('success', 'Query updated successfully.');
}
public function destroy(Query $query)
{
$query->delete();
return redirect()->route('queries.index')->with('success', 'Query deleted successfully.');
}
}

SearchResultController


namespace App\Http\Controllers;
use App\Models\SearchResult;
use App\Models\Query;
use App\Models\IndexedPage;
use Illuminate\Http\Request;
class SearchResultController extends Controller
{
public function index()
{
$searchResults = SearchResult::all();
return view('search_results.index', compact('searchResults'));
}
public function create()
{
$queries = Query::all();
$indexedPages = IndexedPage::all();
return view('search_results.create', compact('queries', 'indexedPages'));
}
public function store(Request $request)
{
$request->validate([
'QueryId' => 'required|exists:queries,QueryId',
'PageId' => 'required|exists:indexed_pages,PageId',
'Rank' => 'nullable|integer',
]);
SearchResult::create($request->all());
return redirect()->route('search_results.index')->with('success', 'Search Result created successfully.');
}
public function show(SearchResult $searchResult)
{
return view('search_results.show', compact('searchResult'));
}
public function edit(SearchResult $searchResult)
{
$queries = Query::all();
$indexedPages = IndexedPage::all();
return view('search_results.edit', compact('searchResult', 'queries', 'indexedPages'));
}
public function update(Request $request, SearchResult $searchResult)
{
$request->validate([
'QueryId' => 'required|exists:queries,QueryId',
'PageId' => 'required|exists:indexed_pages,PageId',
'Rank' => 'nullable|integer',
]);
$searchResult->update($request->all());
return redirect()->route('search_results.index')->with('success', 'Search Result updated successfully.');
}
public function destroy(SearchResult $searchResult)
{
$searchResult->delete();
return redirect()->route('search_results.index')->with('success', 'Search Result deleted successfully.');
}
}

CacheItemController


// app/Http/Controllers/CacheItemController.php
namespace App\Http\Controllers;
use App\Models\CacheItem;
use Illuminate\Http\Request;
class CacheItemController extends Controller
{
public function index()
{
$cacheItems = CacheItem::all();
return view('cache_items.index', compact('cacheItems'));
}
public function create()
{
return view('cache_items.create');
}
public function store(Request $request)
{
$request->validate([
'Key' => 'required|unique:cache_items,Key|max:255',
'Value' => 'nullable',
'Expiration' => 'nullable|date',
]);
CacheItem::create($request->all());
return redirect()->route('cache_items.index')->with('success', 'Cache Item created successfully.');
}
public function show(CacheItem $cacheItem)
{
return view('cache_items.show', compact('cacheItem'));
}
public function edit(CacheItem $cacheItem)
{
return view('cache_items.edit', compact('cacheItem'));
}
public function update(Request $request, CacheItem $cacheItem)
{
$request->validate([
'Key' => 'required|max:255|unique:cache_items,Key,' . $cacheItem->id,
'Value' => 'nullable',
'Expiration' => 'nullable|date',
]);
$cacheItem->update($request->all());
return redirect()->route('cache_items.index')->with('success', 'Cache Item updated successfully.');
}
public function destroy(CacheItem $cacheItem)
{
$cacheItem->delete();
return redirect()->route('cache_items.index')->with('success', 'Cache Item deleted successfully.');
}
}

AnalyticsDataController


// app/Http/Controllers/AnalyticsDataController.php
namespace App\Http\Controllers;
use App\Models\AnalyticsData;
use App\Models\Query;
use Illuminate\Http\Request;
class AnalyticsDataController extends Controller
{
public function index()
{
$analyticsData = AnalyticsData::all();
return view('analytics_data.index', compact('analyticsData'));
}
public function create()
{
$queries = Query::all();
return view('analytics_data.create', compact('queries'));
}
public function store(Request $request)
{
$request->validate([
'QueryId' => 'required|exists:queries,QueryId',
'Clicks' => 'nullable|integer',
'Impressions' => 'nullable|integer',
]);
AnalyticsData::create($request->all());
return redirect()->route('analytics_data.index')->with('success', 'Analytics Data created successfully.');
}
public function show(AnalyticsData $analyticsData)
{
return view('analytics_data.show', compact('analyticsData'));
}
public function edit(AnalyticsData $analyticsData)
{
$queries = Query::all();
return view('analytics_data.edit', compact('analyticsData', 'queries'));
}
public function update(Request $request, AnalyticsData $analyticsData)
{
$request->validate([
'QueryId' => 'required|exists:queries,QueryId',
'Clicks' => 'nullable|integer',
'Impressions' => 'nullable|integer',
]);
$analyticsData->update($request->all());
return redirect()->route('analytics_data.index')->with('success', 'Analytics Data updated successfully.');
}
public function destroy(AnalyticsData $analyticsData)
{
$analyticsData->delete();
return redirect()->route('analytics_data.index')->with('success', 'Analytics Data deleted successfully.');
}
}

FeedbackController


// app/Http/Controllers/FeedbackController.php
namespace App\Http\Controllers;
use App\Models\Feedback;
use App\Models\User;
use Illuminate\Http\Request;
class FeedbackController extends Controller
{
public function index()
{
$feedbacks = Feedback::all();
return view('feedbacks.index', compact('feedbacks'));
}
public function create()
{
$users = User::all();
return view('feedbacks.create', compact('users'));
}
public function store(Request $request)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'Comments' => 'nullable',
'Rating' => 'required|integer|between:1,5',
]);
Feedback::create($request->all());
return redirect()->route('feedbacks.index')->with('success', 'Feedback created successfully.');
}
public function show(Feedback $feedback)
{
return view('feedbacks.show', compact('feedback'));
}
public function edit(Feedback $feedback)
{
$users = User::all();
return view('feedbacks.edit', compact('feedback', 'users'));
}
public function update(Request $request, Feedback $feedback)
{
$request->validate([
'User Id' => 'required|exists:users,User Id',
'Comments' => 'nullable',
'Rating' => 'required|integer|between:1,5',
]);
$feedback->update($request->all());
return redirect()->route('feedbacks.index')->with('success', 'Feedback updated successfully.');
}
public function destroy(Feedback $feedback)
{
$feedback->delete();
return redirect()->route('feedbacks.index')->with('success', 'Feedback deleted successfully.');
}
}

SecuritySettingController


// app/Http/Controllers/SecuritySettingController.php
namespace App\Http\Controllers;
use App\Models\SecuritySetting;
use Illuminate\Http\Request;
class SecuritySettingController extends Controller
{
public function index()
{
$securitySettings = SecuritySetting::all();
return view('security_settings.index', compact('securitySettings'));
}
public function create()
{
return view('security_settings.create');
}
public function store(Request $request)
{
$request->validate([
'SettingName' => 'required|unique:security_settings,SettingName|max:100',
'SettingValue' => 'nullable|max:255',
]);
SecuritySetting::create($request->all());
return redirect()->route('security_settings.index')->with('success', 'Security Setting created successfully.');
}
public function show(SecuritySetting $securitySetting)
{
return view('security_settings.show', compact('securitySetting'));
}
public function edit(SecuritySetting $securitySetting)
{
return view('security_settings.edit', compact('securitySetting'));
}
public function update(Request $request, SecuritySetting $securitySetting)
{
$request->validate([
'SettingName' => 'required|max:100|unique:security_settings,SettingName,' . $securitySetting->id,
'SettingValue' => 'nullable|max:255',
]);
$securitySetting->update($request->all());
return redirect()->route('security_settings.index')->with('success', 'Security Setting updated successfully.');
}
public function destroy(SecuritySetting $securitySetting)
{
$securitySetting->delete();
return redirect()->route('security_settings.index')->with('success', 'Security Setting deleted successfully.');
}
}

With these controllers, you now have a complete set of CRUD operations for each model in your Laravel application. You can further customize the views and add any additional functionality as needed.

Creating view files for each controller using Bootstrap 5

Creating a set of Blade templates in Laravel involves creating a directory for each model's views under resources/views. For example, you can create directories like users, roles, urls, etc. Each directory will contain the corresponding view files.

Step 1: Create View Files

Directory Structure


resources
└── views
├── users
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── roles
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── urls
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── indexed_pages
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── queries
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── search_results
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── cache_items
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── analytics_data
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
├── feedbacks
│ ├── index.blade.php
│ ├── create.blade.php
│ ├── edit.blade.php
│ ├── show.blade.php
└── security_settings
├── index.blade.php
├── create.blade.php
├── edit.blade.php
└── show.blade.php

Step 2: Create View Files

Below are the basic implementations for each view file using Bootstrap 5.

User Views

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>
<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.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
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
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 }}" {{ $user->RoleId == $role->RoleId ? 'selected' : '' }}>{{ $role->RoleName }}</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Update User</button>
</form>
</div>
@endsection
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>
<form action="{{ route('users.destroy', $user) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('users.index') }}" class="btn btn-secondary">Back to Users</a>
</div>
@endsection

Role Views

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>
<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.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
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
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-primary">Update Role</button>
</form>
</div>
@endsection
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>
<form action="{{ route('roles.destroy', $role) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('roles.index') }}" class="btn btn-secondary">Back to Roles</a>
</div>
@endsection

URL Views

index.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>URLs</h1>
<a href="{{ route('urls.create') }}" class="btn btn-primary mb-3">Create URL</a>
<table class="table">
<thead>
<tr>
<th>URL</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($urls as $url)
<tr>
<td>{{ $url->URL }}</td>
<td>{{ $url->Status }}</td>
<td>
<a href="{{ route('urls.edit', $url) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('urls.destroy', $url) }}" 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
create.blade.php

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

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit URL</h1>
<form action="{{ route('urls.update', $url) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="URL" class="form-label">URL</label>
<input type="url" class="form-control" id="URL" name="URL" value="{{ $url->URL }}" 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="{{ $url->Status }}">
</div>
<button type="submit" class="btn btn-primary">Update URL</button>
</form>
</div>
@endsection
show.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>URL Details</h1>
<p><strong>URL:</strong> {{ $url->URL }}</p>
<p><strong>Status:</strong> {{ $url->Status }}</p>
<a href="{{ route('urls.edit', $url) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('urls.destroy', $url) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('urls.index') }}" class="btn btn-secondary">Back to URLs</a>
</div>
@endsection

Indexed Page Views

index.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Indexed Pages</h1>
<a href="{{ route('indexed_pages.create') }}" class="btn btn-primary mb-3">Create Indexed Page</a>
<table class="table">
<thead>
<tr>
<th>URL</th>
<th>Title</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($indexedPages as $indexedPage)
<tr>
<td>{{ $indexedPage->url->URL ?? 'N/A' }}</td>
<td>{{ $indexedPage->Title }}</td>
<td>
<a href="{{ route('indexed_pages.edit', $indexedPage) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('indexed_pages.destroy', $indexedPage) }}" 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
create.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Indexed Page</h1>
<form action="{{ route('indexed_pages.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="URLId" class="form-label">URL</label>
<select class="form-select" id="URLId" name="URLId" required>
<option value="">Select URL</option>
@foreach ($urls as $url)
<option value="{{ $url->URLId }}">{{ $url->URL }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Title" class="form-label">Title</label>
<input type="text" class="form-control" id="Title" name="Title">
</div>
<div class="mb-3">
<label for="Content" class="form-label">Content</label>
<textarea class="form-control" id="Content" name="Content"></textarea>
</div>
<div class="mb-3">
<label for="MetaDescription" class="form-label">Meta Description</label>
<input type="text" class="form-control" id="MetaDescription" name="MetaDescription">
</div>
<button type="submit" class="btn btn-primary">Create Indexed Page</button>
</form>
</div>
@endsection
edit.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Indexed Page</h1>
<form action="{{ route('indexed_pages.update', $indexedPage) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="URLId" class="form-label">URL</label>
<select class="form-select" id="URLId" name="URLId" required>
@foreach ($urls as $url)
<option value="{{ $url->URLId }}" {{ $indexedPage->URLId == $url->URLId ? 'selected' : '' }} >{{ $url->URL }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Title" class="form-label">Title</label>
<input type="text" class="form-control" id="Title" name="Title" value="{{ $indexedPage->Title }}">
</div>
<div class="mb-3">
<label for="Content" class="form-label">Content</label>
<textarea class="form-control" id="Content" name="Content">{{ $indexedPage->Content }}</textarea>
</div>
<div class="mb-3">
<label for="MetaDescription" class="form-label">Meta Description</label>
<input type="text" class="form-control" id="MetaDescription" name="MetaDescription" value="{{ $indexedPage->MetaDescription }}">
</div>
<button type="submit" class="btn btn-primary">Update Indexed Page</button>
</form>
</div>
@endsection
show.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Indexed Page Details</h1>
<p><strong>URL:</strong> {{ $indexedPage->url->URL ?? 'N/A' }}</p>
<p><strong>Title:</strong> {{ $indexedPage->Title }}</p>
<p><strong>Content:</strong> {{ $indexedPage->Content }}</p>
<p><strong>Meta Description:</strong> {{ $indexedPage->MetaDescription }}</p>
<a href="{{ route('indexed_pages.edit', $indexedPage) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('indexed_pages.destroy', $indexedPage) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('indexed_pages.index') }}" class="btn btn-secondary">Back to Indexed Pages</a>
</div>
@endsection

Query Views

index.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Queries</h1>
<a href="{{ route('queries.create') }}" class="btn btn-primary mb-3">Create Query</a>
<table class="table">
<thead>
<tr>
<th>User</th>
<th>Search Term</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($queries as $query)
<tr>
<td>{{ $query->user->Username ?? 'N/A' }}</td>
<td>{{ $query->SearchTerm }}</td>
<td>
<a href="{{ route('queries.edit', $query) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('queries.destroy', $query) }}" 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
create.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Query</h1>
<form action="{{ route('queries.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" required>
<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="SearchTerm" class="form-label">Search Term</label>
<input type="text" class="form-control" id="SearchTerm" name="SearchTerm" required>
</div>
<button type="submit" class="btn btn-primary">Create Query</button>
</form>
</div>
@endsection
edit.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Query</h1>
<form action="{{ route('queries.update', $query) }}" 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" required>
@foreach ($users as $user)
<option value="{{ $user->User Id }}" {{ $query->User Id == $user->User Id ? 'selected' : '' }}>{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="SearchTerm" class="form-label">Search Term</label>
<input type="text" class="form-control" id="SearchTerm" name="SearchTerm" value="{{ $query->SearchTerm }}" required>
</div>
<button type="submit" class="btn btn-primary">Update Query</button>
</form>
</div>
@endsection
show.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Query Details</h1>
<p><strong>User:</strong> {{ $query->user->Username ?? 'N/A' }}</p>
<p><strong>Search Term:</strong> {{ $query->SearchTerm }}</p>
<a href="{{ route('queries.edit', $query) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('queries.destroy', $query) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('queries.index') }}" class="btn btn-secondary">Back to Queries</a>
</div>
@endsection

Search Result Views

index.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Search Results</h1>
<a href="{{ route('search_results.create') }}" class="btn btn-primary mb-3">Create Search Result</a>
<table class="table">
<thead>
<tr>
<th>Query</th>
<th>Page</th>
<th>Rank</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($searchResults as $searchResult)
<tr>
<td>{{ $searchResult->query->SearchTerm ?? 'N/A' }}</td>
<td>{{ $searchResult->page->Title ?? 'N/A' }}</td>
<td>{{ $searchResult->Rank }}</td>
<td>
<a href="{{ route('search_results.edit', $searchResult) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('search_results.destroy', $searchResult) }}" 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
create.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Search Result</h1>
<form action="{{ route('search_results.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="QueryId" class="form-label">Query</label>
<select class="form-select" id="QueryId" name="QueryId" required>
<option value="">Select Query</option>
@foreach ($queries as $query)
<option value="{{ $query->QueryId }}">{{ $query->SearchTerm }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="PageId" class="form-label">Page</label>
<select class="form-select" id="PageId" name="PageId" required>
<option value="">Select Page</option>
@foreach ($indexedPages as $indexedPage)
<option value="{{ $indexedPage->PageId }}">{{ $indexedPage->Title }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Rank" class="form-label">Rank</label>
<input type="number" class="form-control" id="Rank" name="Rank">
</div>
<button type="submit" class="btn btn-primary">Create Search Result</button>
</form>
</div>
@endsection
edit.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Search Result</h1>
<form action="{{ route('search_results.update', $searchResult) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="QueryId" class="form-label">Query</label>
<select class="form-select" id="QueryId" name="QueryId" required>
@foreach ($queries as $query)
<option value="{{ $query->QueryId }}" {{ $searchResult->QueryId == $query->QueryId ? 'selected' : '' }}>{{ $query->SearchTerm }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="PageId" class="form-label">Page</label>
<select class="form-select" id="PageId" name="PageId" required>
@foreach ($indexedPages as $indexedPage)
<option value="{{ $indexedPage->PageId }}" {{ $searchResult->PageId == $indexedPage->PageId ? 'selected' : '' }}>{{ $indexedPage->Title }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Rank" class="form-label">Rank</label>
<input type="number" class="form-control" id="Rank" name="Rank" value="{{ $searchResult->Rank }}">
</div>
<button type="submit" class="btn btn-primary">Update Search Result</button>
</form>
</div>
@endsection
show.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Search Result Details</h1>
<p><strong>Query:</strong> {{ $searchResult->query->SearchTerm ?? 'N/A' }}</p>
<p><strong>Page:</strong> {{ $searchResult->page->Title ?? 'N/A' }}</p>
<p><strong>Rank:</strong> {{ $searchResult->Rank }}</p>
<a href="{{ route('search_results.edit', $searchResult) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('search_results.destroy', $searchResult) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('search_results.index') }}" class="btn btn-secondary">Back to Search Results</a>
</div>
@endsection

Cache Item Views

index.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Cache Items</h1>
<a href="{{ route('cache_items.create') }}" class="btn btn-primary mb-3">Create Cache Item</a>
<table class="table">
<thead>
<tr>
<th>Key</th>
<th>Value</th>
<th>Expiration</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($cacheItems as $cacheItem)
<tr>
<td>{{ $cacheItem->Key }}</td>
<td>{{ $cacheItem->Value }}</td>
<td>{{ $cacheItem->Expiration }}</td>
<td>
<a href="{{ route('cache_items.edit', $cacheItem) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('cache_items.destroy', $cacheItem) }}" 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
create.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Cache Item</h1>
<form action="{{ route('cache_items.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="Key" class="form-label">Key</label>
<input type="text" class="form-control" id="Key" name="Key" required>
</div>
<div class="mb-3">
<label for="Value" class="form-label">Value</label>
<input type="text" class="form-control" id="Value" name="Value">
</div>
<div class="mb-3">
<label for="Expiration" class="form-label">Expiration</label>
<input type="datetime-local" class="form-control" id="Expiration" name="Expiration">
</div>
<button type="submit" class="btn btn-primary">Create Cache Item</button>
</form>
</div>
@endsection
edit.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Cache Item</h1>
<form action="{{ route('cache_items.update', $cacheItem) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="Key" class="form-label">Key</label>
<input type="text" class="form-control" id="Key" name="Key" value="{{ $cacheItem->Key }}" required>
</div>
<div class="mb-3">
<label for="Value" class="form-label">Value</label>
<input type="text" class="form-control" id="Value" name="Value" value="{{ $cacheItem->Value }}">
</div>
<div class="mb-3">
<label for="Expiration" class="form-label">Expiration</label>
<input type="datetime-local" class="form-control" id="Expiration" name="Expiration" value="{{ $cacheItem->Expiration }}">
</div>
<button type="submit" class="btn btn-primary">Update Cache Item</button>
</form>
</div>
@endsection
show.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Cache Item Details</h1>
<p><strong>Key:</strong> {{ $cacheItem->Key }}</p>
<p><strong>Value:</strong> {{ $cacheItem->Value }}</p>
<p><strong>Expiration:</strong> {{ $cacheItem->Expiration }}</p>
<a href="{{ route('cache_items.edit', $cacheItem) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('cache_items.destroy', $cacheItem) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('cache_items.index') }}" class="btn btn-secondary">Back to Cache Items</a>
</div>
@endsection

Analytics Data Views

index.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Analytics Data</h1>
<a href="{{ route('analytics_data.create') }}" class="btn btn-primary mb-3">Create Analytics Data</a>
<table class="table">
<thead>
<tr>
<th>Query</th>
<th>Clicks</th>
<th>Impressions</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($analyticsData as $data)
<tr>
<td>{{ $data->query->SearchTerm ?? 'N/A' }}</td>
<td>{{ $data->Clicks }}</td>
<td>{{ $data->Impressions }}</td>
<td>
<a href="{{ route('analytics_data.edit', $data) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('analytics_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
create.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Analytics Data</h1>
<form action="{{ route('analytics_data.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="QueryId" class="form-label">Query</label>
<select class="form-select" id="QueryId" name="QueryId" required>
<option value="">Select Query</option>
@foreach ($queries as $query)
<option value="{{ $query->QueryId }}">{{ $query->SearchTerm }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Clicks" class ="form-label">Clicks</label>
<input type="number" class="form-control" id="Clicks" name="Clicks">
</div>
<div class="mb-3">
<label for="Impressions" class="form-label">Impressions</label>
<input type="number" class="form-control" id="Impressions" name="Impressions">
</div>
<button type="submit" class="btn btn-primary">Create Analytics Data</button>
</form>
</div>
@endsection
edit.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Analytics Data</h1>
<form action="{{ route('analytics_data.update', $analyticsData) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="QueryId" class="form-label">Query</label>
<select class="form-select" id="QueryId" name="QueryId" required>
@foreach ($queries as $query)
<option value="{{ $query->QueryId }}" {{ $analyticsData->QueryId == $query->QueryId ? 'selected' : '' }}>{{ $query->SearchTerm }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Clicks" class="form-label">Clicks</label>
<input type="number" class="form-control" id="Clicks" name="Clicks" value="{{ $analyticsData->Clicks }}">
</div>
<div class="mb-3">
<label for="Impressions" class="form-label">Impressions</label>
<input type="number" class="form-control" id="Impressions" name="Impressions" value="{{ $analyticsData->Impressions }}">
</div>
<button type="submit" class="btn btn-primary">Update Analytics Data</button>
</form>
</div>
@endsection
show.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Analytics Data Details</h1>
<p><strong>Query:</strong> {{ $analyticsData->query->SearchTerm ?? 'N/A' }}</p>
<p><strong>Clicks:</strong> {{ $analyticsData->Clicks }}</p>
<p><strong>Impressions:</strong> {{ $analyticsData->Impressions }}</p>
<a href="{{ route('analytics_data.edit', $analyticsData) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('analytics_data.destroy', $analyticsData) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('analytics_data.index') }}" class="btn btn-secondary">Back to Analytics Data</a>
</div>
@endsection

Feedback Views

index.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Feedbacks</h1>
<a href="{{ route('feedbacks.create') }}" class="btn btn-primary mb-3">Create Feedback</a>
<table class="table">
<thead>
<tr>
<th>User</th>
<th>Comments</th>
<th>Rating</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($feedbacks as $feedback)
<tr>
<td>{{ $feedback->user->Username ?? 'N/A' }}</td>
<td>{{ $feedback->Comments }}</td>
<td>{{ $feedback->Rating }}</td>
<td>
<a href="{{ route('feedbacks.edit', $feedback) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('feedbacks.destroy', $feedback) }}" 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
create.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Feedback</h1>
<form action="{{ route('feedbacks.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" required>
<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="Comments" class="form-label">Comments</label>
<textarea class="form-control" id="Comments" name="Comments"></textarea>
</div>
<div class="mb-3">
<label for="Rating" class="form-label">Rating</label>
<input type="number" class="form-control" id="Rating" name="Rating" min="1" max="5" required>
</div>
<button type="submit" class="btn btn-primary">Create Feedback</button>
</form>
</div>
@endsection
edit.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Feedback</h1>
<form action="{{ route('feedbacks.update', $feedback) }}" 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" required>
@foreach ($users as $user)
<option value="{{ $user->User Id }}" {{ $feedback->User Id == $user->User Id ? 'selected' : '' }}>{{ $user->Username }}</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="Comments" class="form-label">Comments</label>
<textarea class="form-control" id="Comments" name="Comments">{{ $feedback->Comments }}</textarea>
</div>
<div class="mb-3">
<label for="Rating" class="form-label">Rating</label>
<input type="number" class="form-control" id="Rating" name="Rating" value="{{ $feedback->Rating }}" min="1" max="5" required>
</div>
<button type="submit" class="btn btn-primary">Update Feedback</button>
</form>
</div>
@endsection
show.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Feedback Details</h1>
<p><strong>User:</strong> {{ $feedback->user->Username ?? 'N/A' }}</p>
<p><strong>Comments:</strong> {{ $feedback->Comments }}</p>
<p><strong>Rating:</strong> {{ $feedback->Rating }}</p>
<a href="{{ route('feedbacks.edit', $feedback) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('feedbacks.destroy', $feedback) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('feedbacks.index') }}" class="btn btn-secondary">Back to Feedbacks</a>
</div>
@endsection

Security Setting Views

index.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Security Settings</h1>
<a href="{{ route('security_settings.create') }}" class="btn btn-primary mb-3">Create Security Setting</a>
<table class="table">
<thead>
<tr>
<th>Setting Name</th>
<th>Setting Value</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($securitySettings as $setting)
<tr>
<td>{{ $setting->SettingName }}</td>
<td>{{ $setting->SettingValue }}</td>
<td>
<a href="{{ route('security_settings.edit', $setting) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('security_settings.destroy', $setting) }}" 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
create.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Create Security Setting</h1>
<form action="{{ route('security_settings.store') }}" method="POST">
@csrf
<div class="mb-3">
<label for="SettingName" class="form-label">Setting Name</label>
<input type="text" class="form-control" id="SettingName" name="SettingName" required>
</div>
<div class="mb-3">
<label for="SettingValue" class="form-label">Setting Value</label>
<input type="text" class="form-control" id="SettingValue" name="SettingValue">
</div>
<button type="submit" class="btn btn-primary">Create Security Setting</button>
</form>
</div>
@endsection
edit.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Edit Security Setting</h1>
<form action="{{ route('security_settings.update', $securitySetting) }}" method="POST">
@csrf
@method('PUT')
<div class="mb-3">
<label for="SettingName" class="form-label">Setting Name</label>
<input type="text" class="form-control" id="SettingName" name="SettingName" value="{{ $securitySetting->SettingName }}" required>
</div>
<div class="mb-3">
<label for="SettingValue" class="form-label">Setting Value</label>
<input type="text" class="form-control" id="SettingValue" name="SettingValue" value="{{ $securitySetting->SettingValue }}">
</div>
<button type="submit" class="btn btn-primary">Update Security Setting</button>
</form>
</div>
@endsection
show.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<h1>Security Setting Details</h1>
<p><strong>Setting Name:</strong> {{ $securitySetting->SettingName }}</p>
<p><strong>Setting Value:</strong> {{ $securitySetting->SettingValue }}</p>
<a href="{{ route('security_settings.edit', $securitySetting) }}" class="btn btn-warning">Edit</a>
<form action="{{ route('security_settings.destroy', $securitySetting) }}" method="POST" style="display:inline;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
<a href="{{ route('security_settings.index') }}" class="btn btn-secondary">Back to Security Settings</a>
</div>
@endsection

With these view files, you now have a complete set of Bootstrap 5-based views for each controller in your Laravel application. You can further customize the styles and layouts as needed.

Creating a layout file in Laravel

Creating a layout file in Laravel allows you to define a common structure for your views, which can help maintain consistency across your application. Below is an example of a layout file using Bootstrap 5. This layout will include a navigation bar, a container for the main content, and links to Bootstrap's CSS.

Step 1: Create the Layout File

You can create a layout file in the resources/views/layouts directory. For example, you can name it app.blade.php.

Directory Structure


resources
└── views
├── layouts
│ └── app.blade.php
├── users
├── roles
├── urls
├── indexed_pages
├── queries
├── search_results
├── cache_items
├── analytics_data
├── feedbacks
└── security_settings

Step 2: Implement the Layout File


<!-- 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 -->
</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('urls.index') }}">URLs</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('indexed_pages.index') }}">Indexed Pages</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('queries.index') }}">Queries</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('search_results.index') }}">Search Results</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('cache_items.index') }}">Cache Items</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('analytics_data.index') }}">Analytics Data</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('feedbacks.index') }}">Feedbacks</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ route('security_settings.index') }}">Security Settings</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-4">
@if(session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif
@if($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
@yield('content')
</div>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.min.js"></script>
</body>
</html>

Step 3: Using the Layout in Views

To use this layout in your views, simply extend it at the top of your Blade files. For example, in the index.blade.php file for users, you would do the following:


@extends('layouts.app')
@section('title', 'User List')
@section('content')
<div class="container">
<h1>Users</h1>
<!-- User content goes here -->
</div>
@endsection

This structure allows you to maintain a consistent look and feel across your application while keeping your code organized and manageable.

To create a dashboard page in Laravel for displaying consolidated project data

You should start by setting up a route and a controller to handle the data retrieval. Then, create a view that utilizes a layout file to present the data in a user-friendly manner. Consider using libraries like Chart.js for visualizations and ensure your dashboard is responsive.

Step 1: Define the Route

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


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

Step 2: Create the Dashboard Controller

Generate a controller using Artisan command:


php artisan make:controller DashboardController

Then, implement the index method in DashboardController.php:


namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Product;
use App\Models\Sale;
class DashboardController extends Controller
{
public function index()
{
$totalProducts = Product::count();
$totalSales = Sale::count();
$totalRevenue = Sale::sum('total');
$totalProfit = Sale::sum('profit');
return view('dashboard.index', compact('totalProducts', 'totalSales', 'totalRevenue', 'totalProfit'));
}
}

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-3">
<div class="card text-white bg-primary mb-3">
<div class="card-header">Total Products</div>
<div class="card-body">
<h5 class="card-title">{{ $totalProducts }}</h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-success mb-3">
<div class="card-header">Total Sales</div>
<div class="card-body">
<h5 class="card-title">{{ $totalSales }}</h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-warning mb-3">
<div class="card-header">Total Revenue</div>
<div class="card-body">
<h5 class="card-title">${{ number_format($totalRevenue, 2) }}</h5>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card text-white bg-danger mb-3">
<div class="card-header">Total Profit</div>
<div class="card-body">
<h5 class="card-title">${{ number_format($totalProfit, 2) }}</h5>
</div>
</div>
</div>
</div>
</div>
@endsection

Step 4: Explanation of the Dashboard View

Card Components: Each card represents a different metric (Total Products, Total Sales, Total Revenue, Total Profit) and uses Bootstrap's card component for styling.

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

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

Step 5: Accessing the Dashboard

You can now access the dashboard by navigating to /dashboard in your web browser. This page will display consolidated data related to your project, providing a quick overview of key metrics.