第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 PHPDoc 中描述控制器查詢參數(shù)

在 PHPDoc 中描述控制器查詢參數(shù)

PHP
臨摹微笑 2022-12-23 13:15:16
我的 Laravel 控制器有一個索引方法,它接受一個可選的查詢字符串參數(shù)。這應該如何在方法的 PHPDoc 塊中表示?雇主控制器.php:/** * @param Request $request * @return Response * Returns list of Employers */public function index(Request $request) {    // This is the optional parameter which needs to be represented    // in the PHPDoc block    $collectiveAgreement = $request->query('collective_agreement');    ...}
查看完整描述

2 回答

?
撒科打諢

TA貢獻1934條經(jīng)驗 獲得超2個贊

如果您的目的是記錄這些字段,我建議創(chuàng)建一個處理所有邏輯的 FormRequest,然后將表單請求注入控制器。這樣,您就知道請求是在哪里形成的,然后去那個類查看字段甚至更好:它們通過驗證的規(guī)則。


php artisan make:request ListUsersRequest

ListUsersRequest.php

namespace App\Http\Requests;


use Illuminate\Foundation\Http\FormRequest;


class ListUsersRequest extends FormRequest {


    public function rules()

    {

        return [

            'collective_agreement' => ['here', 'goes', 'your', 'rules'],

            'another_field'        => ['here', 'goes', 'more', 'rules'],

        ];

    }


    public function authorize()

    {

        return true;

    }

}

然后,回到你的控制器


用戶控制器.php

public function index(ListUsersRequest $request)

{   //                ^^^^^^^^^^^^^^^^

    $data = $request->validated();

    $collectiveAgreement = $data['collective_agreement'];

//  Or as you did:   

//  $collectiveAgreement = $request->query('collective_agreement');

}


查看完整回答
反對 回復 2022-12-23
?
三國紛爭

TA貢獻1804條經(jīng)驗 獲得超7個贊

將描述放在第一行@param及其@return下方。這將是一種標準順序。隨意添加描述,以及它如何幫助其他閱讀代碼的人。在這種情況下,您已經(jīng)記錄了參數(shù),因為該查詢字符串是$request對象的一部分,但您可以將描述擴展為:


/**

 * Returns list of Employers. 

 * Request object may have optional query string parameter 'collective_agreement'

 * used for this and this and that and that

 *

 * @param Request $request

 * @return Response

 */

public function index(Request $request)

{

    // This is the optional parameter which needs to be represented

    // in the PHPDoc block

    $collectiveAgreement = $request->query('collective_agreement');

    ...

}


查看完整回答
反對 回復 2022-12-23
  • 2 回答
  • 0 關(guān)注
  • 103 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號