×ðÁú¿­Ê±

laravel·ÖÒ³Ôõô´ø²ÎÊý

ÔÚʹÓà laravel ·ÖÒ³¹¦Ð§Ê±£¬ÎÒÃÇ¿ÉÄÜÐèÒªÔÚÿ¸öÒ³ÃæÖÐЯ´øһЩ²ÎÊý£¬ºÃ±ÈËÑË÷Òªº¦×Ö¡¢ÅÅÐò·½·¨µÈµÈ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚ laravel ÖÐʵÏÖ´ø²ÎÊýµÄ·ÖÒ³¹¦Ð§¡£

Ê×ÏÈ£¬ÎÒÃÇÐèÒªÏàʶ Laravel ·ÖÒ³¹¦Ð§µÄ»ù±¾Ó÷¨¡£ÔÚ¿ØÖÆÆ÷ÖÐʹÓÃÒÔÏ´úÂë¼´¿É¶ÔÊý¾Ý¾ÙÐзÖÒ³£º

use Illuminate\Pagination\Paginator;

$data = DB::table('table_name')->paginate(10);
return view('view_name', ['data' => $data]);

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬½«´Ó±í table_name ÖлñÈ¡ËùÓÐÊý¾Ý£¬²¢½«Æä·ÖÒ³ÏÔʾ£¬Ã¿Ò³ÏÔʾ 10 ÌõÊý¾Ý¡£×îÖÕ½«·ÖÒ³Êý¾Ýת´ïµ½ÊÓͼҳÃæ view_name ÖУ¬±äÁ¿ÃûΪ data¡£

ÈôÊÇÎÒÃÇÐèÒªÔÚ·ÖÒ³Á´½ÓÖÐЯ´ø²ÎÊý£¬¿ÉÒÔÔÚÊÓͼҳÃæÖÐʹÓà Laravel ÌṩµÄ appends() ÒªÁì¡£ÀýÈ磬ÎÒÃÇÐèÒªÔÚ·ÖÒ³Á´½ÓÖÐЯ´øÒ»¸öÃûΪ search µÄËÑË÷Òªº¦×Ö²ÎÊý£¬¿ÉÒÔÔÚÊÓͼҳÃæÖÐÕâÑùд£º

{{ $data->appends(['search' => $keyword])->links() }}

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬$keyword ΪËÑË÷Òªº¦×Ö¡£appends() ÒªÁì½ÓÊÜÒ»¸öÊý×é²ÎÊý£¬½«ÆäÖеļüÖµ¶ÔÌí¼Óµ½·ÖÒ³Á´½ÓÖС£links() ÒªÁ콫ÉúÒòËØÒ³Á´½Ó¡£

ÉÏÊö´úÂ뽫ÌìÉúÀàËÆÈçϵķÖÒ³Á´½Ó£º

http://example.com?page=2&search=keyword

µÇ¼ºó¸´ÖÆ

ÕâÑù£¬ÔÚÿҳÖеã»÷·ÖÒ³Á´½Óʱ£¬ËÑË÷Òªº¦×Ö²ÎÊý search=keyword ½«»á×Ô¶¯Ð¯´øµ½Á´½ÓÖС£

³ýÁËЯ´øµ¥¸ö²ÎÊý£¬ÎÒÃÇ»¹¿ÉÒÔͬʱЯ´ø¶à¸ö²ÎÊý¡£ÀýÈ磬ÎÒÃÇÐèÒªÔÚ·ÖÒ³Á´½ÓÖÐЯ´øÒ»¸öÃûΪ search µÄËÑË÷Òªº¦×Ö²ÎÊýºÍÒ»¸öÃûΪ sort µÄÅÅÐò·½·¨²ÎÊý£¬¿ÉÒÔÕâÑùд£º

{{ $data->appends(['search' => $keyword, 'sort' => $sort])->links() }}

µÇ¼ºó¸´ÖÆ

ÔÚ¿ØÖÆÆ÷ÖлñÈ¡ÕâЩ²ÎÊýºÜÊǼòÆÓ£¬Ö»ÐèʹÓà Laravel ÌṩµÄ request() ÒªÁì¼´¿É¡£ÀýÈ磬»ñÈ¡ÃûΪ search µÄËÑË÷Òªº¦×Ö²ÎÊýºÍÃûΪ sort µÄÅÅÐò·½·¨²ÎÊý£¬¿ÉÒÔÕâÑùд£º

$search = request('search');
$sort = request('sort');

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂ뽫»®·Ö»ñÈ¡ÃûΪ search ºÍ sort µÄ²ÎÊýÖµ£¬ÈôÊDz»±£´æÔòĬÒÔΪ null¡£

ÔÚ Laravel ÖÐʵÏÖ´ø²ÎÊýµÄ·ÖÒ³¹¦Ð§ºÜÊǼòÆÓ£¬Ö»ÐèʹÓà appends() ÒªÁì¼´¿ÉÇáËÉЯ´ø²ÎÊý¡£ÔÚÕÆÎÕÁË»ù±¾Ó÷¨Ö®ºó£¬ÎÒÃÇ¿ÉÒÔƾ֤ÏêϸÏÖʵÐèÇó×ÔÓɶ¨ÖƲÎÊý¼°ÆäÖµ£¬ÊµÏÖÔ½·¢ÎÞаµÄ·ÖÒ³¹¦Ð§¡£

ÒÔÉϾÍÊÇlaravel·ÖÒ³Ôõô´ø²ÎÊýµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

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

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

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿