Basic Laravel Training (for CV)

From Ta Wiki
Revision as of 19:20, 7 March 2019 by Tata (talk | contribs)
Jump to navigation Jump to search

Reference

  • Laravel Documentation
https://laravel.com/docs/5.8

Installation

Requirements

  • PHP >= 7.1.3
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension
  • BCMath PHP Extension

Steps

  1. Install LAMP Stack (ie. XAMPP) อย่าลืมจำ mysql root password!!
  2. Install Composer
    https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos
    หมายเหตุ: เวลาเรียกใช้งาน composer อาจจะต้องใช้ ./composer.phar แทนที่ composer ถ้าทำการ Install composer เป็น local
  3. สร้าง Laravel Project โดยใช้ composer
    composer create-project --prefer-dist laravel/laravel PROJECT_NAME 
  4. Run Local Development Server
    php artisan serve # for running on localhost:8000
    or
    php artisan serve --port=8888 # for running on localhost:8888

Basic Tutorial

Important directory / file

  • app Where the models are
    • Http
      • Controllers
      • Middleware
  • config
  • database
  • public Where the public files (ie. css, js)
  • resources
    • views
  • routes
    • api.php
    • web.php
  • vendor Where the additional libraries store
  • .env all environment variables (ie. DB username/password)

Intro

Controller & Route

  1. Let's make a controller: page_controller
    php artisan make:controller CONTROLLER_NAME
    จะมีไฟล์ app/Http/Controllers/page_controller.php ปรากฎ
  2. ในไฟล์จะมี code เหล่านี้
     1 <?php
     2 
     3 namespace App\Http\Controllers;
     4 
     5 use Illuminate\Http\Request;
     6 
     7 class page_controller extends Controller
     8 {
     9     //
    10 }
    
  3. ลองสร้าง method index

View (Blade Template)

Database

Model & DB

  • php artisan make:model MODEL_NAME --migration
  • php artisan make:migration MIGRATION_NAME

Eloquent

Handle CRUD

  • php artisan make:controller CONTROLLER_NAME --resource
  • method: get, post, patch, delete
  • Route::resource('ROUTE', 'CONTROLLER');

Authentication

User System

Access Control