今天來建立一下Laravel的Controller,
顧名思義,Controller就是用來處理網頁的要求邏輯
這個也是很神奇,居然又是用cmd下指令
就可以生出一個大致完整的Controller出來
建立出來的Controller裡面就包含好幾個function
有index、create、store、show、edit、update、destroy
喔這個就比我自己平常開發網站管理後台基本用到的還多
多到我不知道怎麼用![]()
先來下指令,再來好好說他自己幫我建立的貼心function用途
好的,沒錯!
就是再度開啟我們的終端機下php artisan make:controller ControllerName --resource --model=ModelName指令
php artisan make:controller HomeController --resource --Home
像這樣
指令結構是
php artisan make:controller {Controller Name} --{option 1} -- {option 2} ...
option有像是自動幫你產生好CRUD方法的 –resource
<?php
namespace App\Http\Controllers; // Controller的命名空間
use Illuminate\Http\Request; // 使用的類別
class PhotoController extends Controller
{
...
}
因為剛剛有下–resource的option,讓他幫我建立上面說到的那幾個方法
他其實上面都有註解每個function的用法
但是我還是一個個來說一下
index:Display a listing of the resource.create:Show the form for creating a new resource.store:Store a newly created resource in storage.show:Display the specified resource.edit:Show the form for editing the specified resource.edit跟update差別喜蝦米?update:Update the specified resource in storage.destroy:Remove the specified resource from storage.好了,今天建立初步的Controller,
改天來建立個註冊登入的,也是都包好的 真的是太神奇了~~