×ðÁú¿­Ê±¹ÙÍøµÇ¼

laravel Òþ²Ø×Ö¶Î

laravelÊÇÒ»¸ö¹ãÊܽӴýµÄphp¿ò¼Ü £¬ËüÌṩÁËÐí¶à±ã½ÝµÄ¹¦Ð§ £¬Ê¹µÃ¿ª·¢ÕßÔÚ¹¹½¨webÓ¦ÓÃʱÄܹ»Ô½·¢¸ßЧ¡¢¿ìËÙµØÍê³ÉʹÃü¡£ÆäÖÐÒ»¸öÖ÷ÒªµÄ¹¦Ð§¾ÍÊÇÒþ²Ø×ֶΣ¨hidden fields£© £¬Ëü¿ÉÒԺܺõر£»¤Êý¾ÝµÄÇå¾²ÐÔºÍ˽ÃÜÐÔ £¬Í¬Ê±Ò²Îª¿ª·¢ÕßÌṩÁ˸ü´óµÄÎÞаÐÔ¡£±¾ÆªÎÄÕ½«»áÏÈÈÝlaravelÔõÑùÒþ²Ø×ֶΡ£

LaravelÊÇÒ»¸öMVCģʽµÄ¿ò¼Ü £¬ÒÔÊÇÔÚ¹¹½¨WebÓ¦ÓÃʱ £¬ÎÒÃÇͨ³£»áʹÓÃEloquent ORMÓëÊý¾Ý¿â¾ÙÐн»»¥ £¬´Ó¶øʵÏÖÊý¾ÝµÄ´æ´¢ºÍ²Ù×÷¡£EloquentÌṩÁËÒ»¸öºÜÊÇÀû±ãµÄ¹¦Ð§ £¬¼´ÊôÐÔ»á¼ûÆ÷£¨Accessor£©¡£Í¨¹ý»á¼ûÆ÷ £¬ÎÒÃÇ¿ÉÒÔÔÚ»ñÈ¡Êý¾Ý¿âÖеÄÊý¾Ýʱ £¬¶ÔÆä¾ÙÐÐÌØÁíÍâ´¦Àí £¬ÀýÈçÃûÌû¯Ê±¼ä¡¢ÅÌËãÖµ¡¢Òþ²Ø×ֶεÈ¡£

ʵÏÖÒþ²Ø×ֶεÄÒªÁìºÜÊǼòÆÓ £¬ÎÒÃÇÖ»ÐèÒªÔÚÄ£×ÓÖнç˵һ¸ö$hiddenÊôÐÔ £¬¼´¿É½«Ö¸¶¨µÄ×ֶδÓJSON»òArrayÊä³öÖÐÒþ²ØÆðÀ´¡£ÀýÈç £¬ÎÒÃÇÓÐÒ»¸öUserÄ£×Ó £¬ÆäÖаüÀ¨ÁËÓû§Ãû¡¢ÃÜÂë¡¢ÓÊÏäµÈÃô¸ÐÐÅÏ¢ £¬ÎÒÃÇ¿ÉÒÔÕâÑù½ç˵£º

<?php

namespace AppModels;

use IlluminateDatabaseEloquentModel;

class User extends Model
{
    // ½ç˵Òþ²Ø×Ö¶ÎÊý×é
    protected $hidden = ['password', 'email'];

    // ... Ê¡ÂÔÆäËû´úÂë
}

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂëÖÐ £¬ÎÒÃÇ˵Ã÷Îú$hiddenÊôÐÔ £¬²¢½«ÃÜÂëºÍÓÊÏäÁÐÃûÌí¼Óµ½Êý×éÖÐ £¬ÕâÑùÔÚÊä³öUserÄ£×ÓµÄJSON»òArrayʱ £¬ÕâЩ×ֶξͻᱻÒþ²ØÆðÀ´ £¬°ü¹ÜÁËÊý¾ÝµÄÇå¾²ÐÔ¡£

³ýÁË$hiddenÊôÐÔ £¬ÎÒÃÇ»¹¿ÉÒÔʹÓÃÊôÐÔ»á¼ûÆ÷£¨Accessor£©À´¸üÎÞаµØ¿ØÖÆÒþ²Ø×ֶΡ£ÀýÈç £¬ÎÒÃǽç˵ÁËÒ»×éGetterÒªÁì £¬ÓÃÓÚ»ñÈ¡ÈçÏÂÃûÌõÄÈÕÆÚ£º

/**
 * »ñÈ¡ÈÕÆÚµÄÃûÌÃ
 */
public function getFormatDateAttribute()
{
    return $this->attributes['date']->format('Y-m-d');
}

µÇ¼ºó¸´ÖÆ

ÔÚÊý¾ÝÊä³öʱ £¬ÎÒÃÇ¿ÉÒÔͨ¹ý»á¼ûÆ÷ΪÕâ¸öÃûÌû¯ºóµÄÈÕÆÚÆðÒ»¸öеÄÃû³Æ £¬²¢½«ÆäÒþ²Ø£º

<?php

namespace AppModels;

use IlluminateDatabaseEloquentModel;

class User extends Model
{
    // ½ç˵Òþ²Ø×Ö¶ÎÊý×é
    protected $hidden = ['password', 'email'];

    // ½ç˵»á¼ûÆ÷
    public function getFormatDateAttribute()
    {
        return $this->attributes['date']->format('Y-m-d');
    }

    // ½ç˵»á¼ûÆ÷
    public function getHiddenFieldsAttribute()
    {
        return ['password', 'email'];
    }

    // ... Ê¡ÂÔÆäËû´úÂë
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖÐ £¬ÎÒÃǽç˵ÁËÒ»¸öеÄÊôÐÔ$hiddenFields £¬Ëü·µ»Ø±»Òþ²ØµÄ×Ö¶ÎÊý×é¡£ÐèҪעÖصÄÊÇ £¬ÎÒÃDz¢Ã»Óн«ÃÜÂëºÍÓÊÏäÁÐÃûÌí¼Óµ½$hiddenÊôÐÔÖÐ £¬¶øÊÇͨ¹ý»á¼ûÆ÷À´ÊµÏÖµÄ £¬ÕâÖÖ·½·¨Ô½·¢ÎÞа £¬Ò²¸üÈÝÒ×¾ÙÐж¨ÖÆ»¯¡£

×ܽáһϠ£¬LaravelÌṩÁ˺ÜÊÇÎÞаµÄÒþ²Ø×ֶι¦Ð§ £¬Ö»ÐèÒªÔÚÄ£×ÓÖÐ˵Ã÷$hiddenÊôÐÔ»ò½ç˵ÊôÐÔ»á¼ûÆ÷ £¬¼´¿É¶Ô×ֶξÙÐÐÒþ²Ø £¬È·±£Êý¾ÝµÄÇå¾²ÐÔºÍ˽ÃÜÐÔ¡£Í¬Ê± £¬Õâ¸ö¹¦Ð§Ò²Îª¿ª·¢ÕßÌṩÁ˺ܺõÄÎÞаÐÔºÍÀ©Õ¹ÐÔ £¬¿ÉÒÔºÜÊÇÀû±ãµØƾ֤ӪҵÐèÇó¾ÙÐж¨ÖÆ»¯¡£

ÒÔÉϾÍÊÇlaravel Òþ²Ø×ֶεÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ