Building a McCance Surfacing Contractor Page Using PHP and Laravel

Introduction

Creating a professional and high-performing website for McCance Surfacing Contractors requires a robust framework that ensures scalability, security, and efficiency. Laravel, a PHP framework, is the ideal choice for developing a surfacing contractor website with features such as contact forms, project galleries, and quote request functionalities.

In this blog, we will explore how to build the McCance Surfacing Contractor Page using PHP and Laravel.


Step 1: Setting Up Laravel

  1. Install Laravel via Composer:

     composer create-project --prefer-dist laravel/laravel mccance-surfacing
    
  2. Configure Environment Variables:

    • Open the .env file and set up the database connection.
    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=mccance_surfacing
    DB_USERNAME=root
    DB_PASSWORD=yourpassword
  1. Run Migrations:

     php artisan migrate
    

Step 2: Creating Models and Database Structure

Define the Service Model

php artisan make:model Service -m

Modify the create_services_table migration file:

public function up()
{
    Schema::create('services', function (Blueprint $table) {
        $table->id();
        $table->string('title');
        $table->text('description');
        $table->string('image');
        $table->timestamps();
    });
}

Run the migration:

php artisan migrate

Step 3: Building the Controller and Routes

Create a new controller:

php artisan make:controller ServiceController

Define routes in routes/web.php:

use App\Http\Controllers\ServiceController;

Route::get('/services', [ServiceController::class, 'index']);
Route::get('/services/{id}', [ServiceController::class, 'show']);

Implement logic in ServiceController.php:

use App\Models\Service;

public function index()
{
    $services = Service::all();
    return view('services.index', compact('services'));
}

public function show($id)
{
    $service = Service::findOrFail($id);
    return view('services.show', compact('service'));
}

Step 4: Creating Views with Blade Templates

services/index.blade.php

@extends('layouts.app')

@section('content')
<h1>Our Services</h1>
<ul>
    @foreach ($services as $service)
        <li>
            <a href="{{ route('services.show', $service->id) }}">
                {{ $service->title }}
            </a>
        </li>
    @endforeach
</ul>
@endsection

services/show.blade.php

@extends('layouts.app')

@section('content')
<h1>{{ $service->title }}</h1>
<p>{{ $service->description }}</p>
<img src="{{ asset('storage/' . $service->image) }}" alt="{{ $service->title }}">
@endsection

Step 5: Contact Form and Quote Request Feature

Generate a new controller for inquiries:

php artisan make:controller InquiryController

Define routes in web.php:

Route::get('/contact', [InquiryController::class, 'create']);
Route::post('/contact', [InquiryController::class, 'store']);

Implement logic in InquiryController.php:

use Illuminate\Http\Request;
use App\Models\Inquiry;

public function store(Request $request)
{
    $request->validate([
        'name' => 'required',
        'email' => 'required|email',
        'message' => 'required',
    ]);

    Inquiry::create($request->all());
    return back()->with('success', 'Inquiry submitted successfully!');
}

Step 6: Deploying the Application

  1. Optimize the Application:

     php artisan optimize
    
  2. Set Up a Web Server (Apache or Nginx)

  3. Configure Laravel Storage for Images:

     php artisan storage:link
    
  4. Deploy with Laravel Forge, DigitalOcean, or AWS


Conclusion

Building the McCance Surfacing Contractors website using Laravel ensures a scalable, secure, and efficient web presence. With proper structuring, dynamic content, and a user-friendly interface, the platform will serve as a reliable tool for customer engagement and business growth.

Looking for more Laravel tips? Stay tuned for our next technical blog!

0
Subscribe to my newsletter

Read articles from Stella Josephine directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Stella Josephine
Stella Josephine