關於request 與response

request 指的是使用者端對網頁做請求(需求)

response指的是伺服器回傳給user的東西

如何去使用request?

這時候我們需要使用一個語法叫做dump

class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \\Illuminate\\Http\\Response
     */
    public function index()
    {
        dump(123);
    }

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/21dc894f-0c8e-414c-9953-116cfc81b3fd/1626792438074.jpg

我們可以透過箭頭是呼叫$Request的參數,這裡使用all

class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \\Illuminate\\Http\\Response
     */
    public function index(Request $Request)
    {
        dump($Request->all());
    }

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5ad78307-e54f-4d4b-8283-c81a1fd81f54/1626792873199.jpg

也能透過一些方式只取得我要的值

class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \\Illuminate\\Http\\Response
     */
    public function index(Request $Request)
    {
        dump($Request->input('name'));
    }

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/b9632354-da10-48b6-bef6-f836d86cc2a9/1626793071021.jpg

如果想帶出網址列參數的資料話~可以使用query,它與all的差別就像是post一樣,傳輸時資料是不會被看到的

class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \\Illuminate\\Http\\Response
     */
    public function index(Request $Request)
    {
        dump($Request->query());
    }

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/bfeefe07-8465-4cb2-bc9a-e583a08595ec/1626793245598.jpg

那什麼是response?

主要就是將結果回傳給前端畫面

class ProductController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \\Illuminate\\Http\\Response
     */
    public function index(Request $Request)
    {
        return 'GOOD';
    }

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/858a5c2e-606f-4ca6-adaf-8bb0405bd38d/1626793442373.jpg