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

laravelÅÌÎÊÖ¸¶¨×Ö¶Î

laravelÊÇÒ»¸öºÜÊÇÊ¢ÐеÄphp¿ò¼Ü£¬¿ÉÒÔ×ÊÖú¿ª·¢Õß¿ìËÙ¹¹½¨webÓ¦ÓóÌÐò ¡£ÆäÖУ¬Êý¾Ý¿âÅÌÎÊÊÇ¿ò¼ÜµÄÖ÷Òª×é³É²¿·Ö ¡£ÔÚlaravelÖУ¬ÅÌÎÊÊý¾Ý¿â¿ÉÒÔʹÓÃÅÌÎʹ¹½¨Æ÷ ¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃlaravelÅÌÎʹ¹½¨Æ÷À´ÅÌÎÊÖ¸¶¨×ֶΠ¡£

ÅÌÎÊËùÓÐ×Ö¶Î

ÔÚLaravelÖУ¬ÈôÊÇÎÒÃÇÏëÅÌÎÊÒ»¸ö±íÖеÄËùÓÐ×ֶΣ¬¿ÉÒÔÖ±½ÓʹÓÃÒÔÏÂÅÌÎʹ¹½¨Æ÷ÒªÁ죺

$data = DB::table('table_name')->get();

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬table_nameÊÇÒªÅÌÎʵıíÃû£¬get()ÒªÁìÌåÏÖÒª»ñÈ¡±íÖеÄËùÓÐÊý¾Ý ¡£

ÅÌÎÊÖ¸¶¨×Ö¶Î

ÈôÊÇÎÒÃÇÖ»ÏëÅÌÎʱíÖеÄÌض¨×ֶΣ¬¿ÉÒÔʹÓÃselect()ÒªÁìÀ´Ñ¡ÔñÐèÒªµÄ×ֶΠ¡£ÏêϸÓï·¨ÈçÏ£º

$data = DB::table('table_name')
            ->select('field1', 'field2', ...)
            ->get();

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬field1¡¢field2µÈÊÇÎÒÃÇÏëÒªÅÌÎʵÄ×Ö¶ÎÃû£¬¶à¸ö×Ö¶ÎÃû¿ÉÒÔʹÓöººÅÍÑÀë ¡£

ÅÌÎʶà¸ö±íÖеÄÖ¸¶¨×Ö¶Î

ÔÚLaravelÖУ¬¶à¸ö±íÖ®¼ä¿ÉÒÔ¾ÙÐйØÁªÅÌÎÊ ¡£ÈôÊÇÎÒÃÇÏëÅÌÎʶà¸ö±íµÄÖ¸¶¨×ֶΣ¬¿ÉÒÔʹÓÃjoin()ÒªÁìÀ´¾ÙÐйØÁªÅÌÎÊ ¡£ÏêϸÓï·¨ÈçÏ£º

$data = DB::table('table1')
            ->leftJoin('table2', 'table1.id', '=', 'table2.table1_id')
            ->select('table1.field1', 'table2.field2', ...)
            ->get();

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬table1ºÍtable2ÊÇÎÒÃÇÒªÅÌÎʵÄÁ½Õűí£¬leftJoin()ÒªÁìÌåÏÖʹÓÃ×óÅþÁ¬¹ØÁªÕâÁ½¸ö±í£¬table1.idºÍtable2.table1_idÊǹØÁªÌõ¼þ£¬select()ÒªÁìÒÀÈ»ÊÇÓÃÀ´Ñ¡ÔñÐèÒªÅÌÎʵÄ×ֶΠ¡£

ʹÓÃÄ£×ÓÀàÅÌÎÊÖ¸¶¨×Ö¶Î

³ýÁËʹÓÃÅÌÎʹ¹½¨Æ÷£¬ÎÒÃÇ»¹¿ÉÒÔʹÓÃÄ£×ÓÀàÀ´ÅÌÎÊÊý¾Ý ¡£Ê×ÏÈÒª½¨ÉèÄ£×ÓÀ࣬Ȼºó¿ÉÒÔʹÓÃselect()ÒªÁìÀ´ÅÌÎÊÖ¸¶¨×ֶΠ¡£ÏêϸÓï·¨ÈçÏ£º

class MyModel extends Model
{
    protected $table = 'table_name';
    protected $fillable = ['field1', 'field2', ...];
}

$data = MyModel::select('field1', 'field2', ...)
               ->get();

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬MyModelÊÇÎÒÃǽ¨ÉèµÄÄ£×ÓÀ࣬table_nameÊÇÓëÄ£×Ó¶ÔÓ¦µÄ±íÃû£¬$fillableÊÇ¿ÉÒÔ¾ÙÐÐÅúÁ¿¸³ÖµµÄ×ֶΠ¡£

×ܽá

ÒÔÉϾÍÊÇʹÓÃLaravelÅÌÎʹ¹½¨Æ÷ÅÌÎÊÖ¸¶¨×ֶεÄÒªÁì ¡£¹ØÓÚÊý¾Ý±íÖÐ×ֶν϶àµÄÇéÐΣ¬ÎÒÃÇ¿ÉÒÔÖ»ÅÌÎÊÐèÒªµÄ×ֶΣ¬ïÔÌ­²»ÐëÒªµÄÅÌÎʺÍ×ÊÔ´ãýÃ𠡣ʹÓÃÄ£×ÓÀàÅÌÎÊÊý¾ÝÒ²ÊÇÒ»ÖÖ¼òÆÓ¸ßЧµÄÅÌÎÊ·½·¨ ¡£ÔÚÏÖʵ¿ª·¢ÖУ¬¿ÉÒÔƾ֤ÏêϸÇéÐÎÑ¡ÔñºÏÊʵÄÅÌÎÊÒªÁì ¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ