Try   HackMD

Laravel建置(表格版)@Limo

tags: Laravel 後端 Limo

A_Laravel建置

01_安裝軟體 (版本:LARAVEL5.0

依照次序將以下軟體安裝好,並以cmd(命令提示字元)指令輸入方式,確保安裝是否成功。

項目 安裝載點 安裝留意
1 xampp xampp 安裝成功才安裝composer
空間不足時
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
2 composer composer 勾選 Add this PHP to your path
cmd check: php -v composer -v
3 node.js node cmd check: npm -v
4 HeidiSQL HeidiSQL
5 VScode VScode
VScode套件表* PHP Extension Pack
* Laravel Extension Pack
* PHP Namespace Resolver
* Material Icon Theme
* Prettier - Code formatter
6 github github
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

02_VScode建立專案

colspan="2" rowspan="2"

VC建立專案
1 開啟VScode
2 開啟欲放置專案之資料夾
3 cmd 安裝laravel
composer global require laravel/installer
4 cmd 建立laravel (2擇1
composer create-project prefer-dist laravel/laravel 專案名稱 "7.*"
composer create-project prefer-dist laravel/laravel:^7.0 專案名稱
⚠ "7.*" 及 :^7.0 為LARAVEL版本
需確認 php 版本符合 laravel 版本,可至官網查詢環境設定,否則會出現如下錯誤
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
5 切換 Folder 至剛建立的專案

03_Github_初次連結

動作 說明 補充
1 開啟github(桌面板) 請登入帳戶
2 建立repository 在目標資料夾(父層) 忽略勾選lavaral
點我看圖
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
4 PUSH & FETCH
CLONE(本地端無建立時)
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

04_Github_重新克隆

github連結專案
1 開啟github
2 執行 npm install
3 複製.env example 並修改檔名為 .env
4 點選 .env這個檔,並在terminal 執行 php artisan key:gen
5 最後在執行 php artisan serve
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

05_專案運行

VC專案運行
1 將 VScode 資料夾指定至剛建立的專案,如圖
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
2 cmd:安裝composer及npm相關套件
composer install
npm install

06_與資料庫建立連線

與資料庫建立連線
1 開啟XAMPP
啟動 My SQL
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
2 開啟HeidSQL
建立連線資料環境(與.env相同)
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
在local右鍵:建立新資料庫
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
3 更改.env設定
將 DB_DATABASE 改成剛剛新建立的資料庫名稱
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
4 cmd:啟動serve
php artisan serve

B_資料庫連結與流程

架構

路由網路架構 用途 檔名格式(.php)/命名方式
1 route 指定路由位置+動作 web
2 controller 定義路由位置執行之動作 TestFileController
3 model 取得資料庫資料 TestFile
migrate 建立/修改資料表 product_datas
4 view 路由位置呈現的畫面 test_index_page.blade
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

建立

路由網路架構 cmd/建立方式
1 route 檔案手動新增
2 controller php artisan make:controller ProductController
3 model php artisan make:model Product
migrate
-建立資料表 php artisan make:migration create_product_datas_table
-新增欄位 php artisan make:migration add_A_to_B_table
-修改欄位 php artisan make:migration remove_A_from_B_table
-更新資料表 php artisan migrate
4 view
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

laravel 實踐參考網站