## !!學習LARAVEL,非常重要的2個觀念!! **約定優於配田中十月一Covention Over Configuration** https://zh.wikipedia.org/zh-tw/%E7%BA%A6%E5%AE%9A%E4%BC%98%E4%BA%8E%E9%85%8D%E7%BD%AE **don't repeat yourself** https://ithelp.ithome.com.tw/articles/10310209 **若以上與可讀性有衝突,以可讀性優先** --- ## ORM #### Object-Relational Mapping (ORM, O/RM, or O/R mapping) 就是將關聯式資料庫映射至物件導向的資料抽象化技術。其理念是將資料庫的內容映射為物件,讓程式開發人員可以用操作物件的方式對資料庫進行操作,而不直接使用SQL語法對資料庫進行操作。讓程式設計師不用管底層的資料庫系統是哪種廠牌或哪個版本的資料庫(如:SQL Server、Oracle、DB2、MySQL、Sybase、DBMaker…),僅須用同一套語法撰寫存取資料庫的邏輯。當底層資料庫的實作品變更時,由於程式設計師並不直接對資料庫進行操作,因此程式內容幾乎不用修改,也就是降低了物件導向程式與資料庫之間的耦合關係。 ## Eloquent ORM (物件關係對映) 將 Active Record 模式 以 PHP 實作,提供一些函數來建立 資料庫 物件之間的關聯。 依照 Active Record 模式的原則,Eloquent ORM 以 類別 代表 資料表,並將這些類別的物件實例與資料表中的單一筆資料做綁定。 --- **看別人的專案** STEP1: 看routes/web.php裡面的設定 LARAVEL框架參考自ruby on Rails。不同語言/框架間的關係: css-> bootstrap / sass js-> jquery php-> laravel ruby->ruby on rails ## Laravel版本10.0 php8.2.4 https://laravel.com/docs/10.x/releases (含各版本支援維護時間) 不推薦使用upgrade,實務上都是用逐頁貼與測試,找到可能哪裡會有問題 https://laravel.com/docs/10.x/upgrade Laravel線上教學影片 https://laracasts.com/ ### 官方文件要熟讀的內容: Getting Started:Installation https://laravel.com/docs/10.x/installation The Basics:Routing https://laravel.com/docs/10.x/routing The Basics:Controllers https://laravel.com/docs/10.x/controllers The Basic:CSRF Protection https://laravel.com/docs/10.x/csrf The Basic:Requests https://laravel.com/docs/10.x/requests The Basic:Views https://laravel.com/docs/10.x/views The Basic:Blade Templates https://laravel.com/docs/10.x/blade The Basic:Session https://laravel.com/docs/10.x/session The Basic:Logging https://laravel.com/docs/10.x/logging Database:Query Builder https://laravel.com/docs/10.x/queries Database:Seeding https://laravel.com/docs/10.x/seeding Database:Migrations https://laravel.com/docs/10.x/migrations Eloquent: Relationships https://laravel.com/docs/10.x/eloquent-relationships --- ## 在專案中建立資料庫及資料表 在phpMyAdmin中建立資料庫名稱 laravel36 設定環境值.env 檔中 DB_DATABASE=laravel36 在bash執行,php artisan migrate 若打yes,laravel會用程式的方式建立預設資料表,存放在 C:\xampp\htdocs\laravel\test082202\database\migrations ![](https://hackmd.io/_uploads/ByxZZR-an.png) #