📘 Module 1: Laravel 11 Setup & Project Introduction

← Back to Course Outline

1. Laravel 11 Installation with Composer

Laravel install කිරීමට Composer භාවිතා කරයි. Composer යනු PHP සඳහා වන dependency manager එකකි. ඔබගේ පරිගණකයේ Composer ස්ථාපනය කර නොමැති නම්, getcomposer.org වෙතින් එය install කරගන්න.

Terminal (Command Prompt හෝ Git Bash) එක open කර පහත command එක run කරන්න. මෙමගින් pos_system නමින් නව Laravel project එකක් නිර්මාණය වේ.

composer create-project laravel/laravel pos_system

2. VS Code Environment Setup

Visual Studio Code (VS Code) යනු අපගේ project එක develop කිරීමට භාවිතා කරන code editor එකයි. ඔබට එය මෙතනින් download කරගත හැක.

VS Code install කළ පසු, පහත extensions ස්ථාපනය කර ගැනීමෙන් ඔබේ කාර්යය පහසු වේ:

  • Laravel Blade Snippets - Blade syntax සඳහා උපකාරී වේ.
  • Laravel Goto View - Controller සිට View file එකට පහසුවෙන් යෑමට.
  • PHP Intelephense - PHP code සඳහා auto-completion සහ error checking.

3. Folder Structure Overview

Laravel project එකේ folder structure එක ගැන මූලික අවබෝධයක් ලබාගනිමු.

  • app/ - අපගේ application එකේ core logic (Models, Controllers) මෙහි අඩංගු වේ.
  • routes/ - Web pages සඳහා URL (web.php) සහ API endpoints (api.php) define කරන්නේ මෙහිය.
  • resources/views/ - HTML/Blade files (අපගේ User Interface) මෙහි තැන්පත් කර ඇත.
  • public/ - CSS, JavaScript, සහ images වැනි public files මෙහි ඇත.
  • .env - Database connection, App URL වැනි Environment configurations මෙහි අඩංගු වේ.

4. Start Development Server

Project එක run කිරීමට, terminal එකේ project directory එකට යන්න (cd pos_system) සහ පහත command එක run කරන්න.

php artisan serve

දැන් ඔබේ web browser එකේ http://127.0.0.1:8000 address එකට ගිය විට Laravel welcome page එක දර්ශනය වනු ඇත.

5. Sinhala Explanation of MVC Concept

MVC (Model-View-Controller) යනු කුමක්ද?

MVC කියන්නේ application එකක් නිර්මාණය කිරීමේදී එහි කොටස් තුනකට වෙන් කර, සංවිධානාත්මකව තබා ගැනීමට යොදාගන්නා ක්‍රමවේදයක් (architectural pattern).

  • Model (මොඩලය): මෙය අපේ data සමග වැඩ කරන කොටසයි. Database එකෙන් දත්ත ගැනීම, අලුත් දත්ත ඇතුලත් කිරීම වැනි දේ කරන්නේ Model එකෙන්. සරලවම, මෙය අපේ app එකේ මොලය වගේ. (උදා: Product, User).
  • View (දර්ශනය): User ට පේන කොටස (User Interface). HTML, CSS වලින් හැදෙන web pages මෙයට අයත් වේ. Model එකෙන් ලැබෙන data user ට ලස්සනට පෙන්වන්නේ View එකෙන්.
  • Controller (පාලකය): Model එකත් View එකත් අතර සම්බන්ධීකාරකයා ලෙස ක්‍රියා කරයි. User කෙනෙක් web page එකකින් යම් request එකක් (උදා: button click) කළ විට, එය භාරගෙන, Model එකෙන් අවශ්‍ය දත්ත ලබාගෙන, එම දත්ත View එකට යවා user ට ප්‍රතිචාරයක් (response) දක්වන්නේ Controller එකෙන්.

උදාහරණයක්: ඔබ Restaurant එකකට ගියාම,

  • ඔබ (User) Menu එක බලලා කෑම order කරනවා.
  • වේටර් (Controller) ඔබේ order එක අරගෙන කුස්සියට දෙනවා.
  • කුස්සිය (Model) කෑම එක හදලා දෙනවා.
  • වේටර් (Controller) ඒ කෑම එක අරන් ඇවිත් ඔබට (View) පිළිගන්වනවා.