PHP Web Framework Laravel CRUD MVC App

Step-by-Step Laravel CRUD
Step-by-Step Laravel CRUD

Live stream set for 2025-09-16 at 14:00:00 Eastern

Ask questions in the live chat about any programming or lifestyle topic.

This livestream will be on YouTube or you can watch below.

Beginner’s Guide to Laravel Framework with a Simple MariaDB Example

Laravel is a modern, open-source PHP web application framework that is known for its elegant syntax and ease of use. If you are coming from a procedural PHP background, Laravel is an excellent way to write cleaner, more maintainable code using Object-Oriented Programming (OOP) concepts.

One of Laravel’s core strengths is that it supports the Model-View-Controller (MVC) architectural pattern, which separates your application into three main components:

  • Model: Handles data and business logic
  • View: Handles the presentation layer (HTML/CSS)
  • Controller: Handles user input and updates the model/view accordingly

Laravel is actively maintained, has strong community support, and can be installed easily using Composer.

Laravel Example Application (CRUD with MariaDB)

In this beginner example, we will create a Laravel application that connects to an existing MariaDB table called people with the following columns:

  • id
  • username
  • name
  • age
  • verified

The application will perform full CRUD operations:

  • Create (Insert)
  • Read (Display)
  • Update
  • Delete

Step 1: Install Laravel Using Composer

composer create-project laravel/laravel laravel-mariadb-app

Step 2: Configure the Database

Update your .env file:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_password

Note: Laravel supports MariaDB since it is a drop-in replacement for MySQL.

Step 3: Create the Model and Controller

php artisan make:model Person -mcr

Update the model app/Models/Person.php:

protected $table = 'people';

protected $fillable = ['username', 'name', 'age', 'verified'];

Step 4: Set Up Routes in routes/web.php

>use App\Http\Controllers\PersonController;

Route::resource('people', PersonController::class);

Step 5: Implement Controller Logic (PersonController.php)

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

class PersonController extends Controller
{
    public function index()
    {
        $people = Person::all();
        return view('people.index', compact('people'));
    }

    public function create()
    {
        return view('people.create');
    }

    public function store(Request $request)
    {
        Person::create($request->all());
        return redirect()->route('people.index');
    }

    public function edit(Person $person)
    {
        return view('people.edit', compact('person'));
    }

    public function update(Request $request, Person $person)
    {
        $person->update($request->all());
        return redirect()->route('people.index');
    }

    public function destroy(Person $person)
    {
        $person->delete();
        return redirect()->route('people.index');
    }
}

Step 6: Create Views (Blade Templates)

Inside resources/views/people folder, create the following files:

  • index.blade.php to list all entries
  • create.blade.php for adding entries
  • edit.blade.php for updating entries

Example for index.blade.php:

<h1>All People</h1>
<a href="{{ route('people.create') }}">Add New Person</a>
<table border="1">
    <tr>
        <th>ID</th>
        <th>Username</th>
        <th>Name</th>
        <th>Age</th>
        <th>Verified</th>
        <th>Actions</th>
    </tr>
    @foreach($people as $person)
    <tr>
        <td>{{ $person->id }}</td>
        <td>{{ $person->username }}</td>
        <td>{{ $person->name }}</td>
        <td>{{ $person->age }}</td>
        <td>{{ $person->verified ? 'Yes' : 'No' }}</td>
        <td>
            <a href="{{ route('people.edit', $person->id) }}">Edit</a>
            <form action="{{ route('people.destroy', $person->id) }}" method="POST" style="display:inline;">
                @csrf
                @method('DELETE')
                <button type="submit">Delete</button>
            </form>
        </td>
    </tr>
    @endforeach
</table>

Screenshots And Screencast

Database Config
Gnome Text Editor Displaying App Database Configuration File

People Controller
Gnome Text Editor Displaying People Controller

People Model
Gnome Text Editor Displaying People Model

People View Index
Gnome Text Editor Displaying App People View Index File

People View Add
Gnome Text Editor Displaying App People View Add File

People View Edit
Gnome Text Editor Displaying App People View Edit File

People Route
Web Browser Displaying App People Route

Created Person Result
Web Browser Displaying Created Person Result

Add Person Form
Web Browser Displaying Add A Person Form

Edit Person Form
Web Browser Displaying Edit A Person Form

Remove Person Prompt
Web Browser Displaying Remove Person Prompt

Custom View Records In Web Browser

Want to Learn More?

If you are interested in mastering PHP and Laravel, check out my book and course:

Need Help?

I am available for:

  • One-on-one programming tutorials
  • Updating or migrating your Laravel or PHP applications

Contact me here

Let me know in the comments if you have any questions or want a follow-up tutorial.

About Edward

Edward is a software engineer, web developer, and author dedicated to helping people achieve their personal and professional goals through actionable advice and real-world tools.

As the author of impactful books including Learning JavaScript, Learning Python, Learning PHP, Mastering Blender Python API, and fiction The Algorithmic Serpent, Edward writes with a focus on personal growth, entrepreneurship, and practical success strategies. His work is designed to guide, motivate, and empower.

In addition to writing, Edward offers professional "full-stack development," "database design," "1-on-1 tutoring," "consulting sessions,", tailored to help you take the next step. Whether you are launching a business, developing a brand, or leveling up your mindset, Edward will be there to support you.

Edward also offers online courses designed to deepen your learning and accelerate your progress. Explore the programming on languages like JavaScript, Python and PHP to find the perfect fit for your journey.

📚 Explore His Books – Visit the Book Shop to grab your copies today.
💼 Need Support? – Learn more about Services and the ways to benefit from his expertise.
🎓 Ready to Learn? – Check out his Online Courses to turn your ideas into results.

Leave a Reply

Your email address will not be published. Required fields are marked *