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

laravelǰ̨½Ó¿ÚÔõôд

laravelÊÇÄ¿½ñºÜÊÇÊ¢ÐеÄphp¿ª·¢¿ò¼Ü£¬Ö§³Ö¿ìËÙ¿ª·¢ºÍЧÀÍÆ÷¶ËÓ¦ÓóÌÐò¹¹½¨¡£ÔÚÏÖʵÏîÄ¿ÖУ¬¿ª·¢Õßͨ³£ÐèÒª±àдǰ̨½Ó¿Ú£¬ÒÔʵÏÖÇ°¶ËºÍºó¶ËµÄÊý¾Ý½»»¥ºÍͨѶ¡£ÏÂÃ潫ÏÈÈÝÔõÑùʹÓÃlaravel¿ò¼Ü±àдǰ̨½Ó¿Ú¡£

Ò»¡¢×°ÖÃLaravel

Ê×ÏÈÐèÒªÔÚÍâµØÇéÐÎ×°ÖÃLaravel¿ò¼Ü¡£¿ÉÒÔÑ¡ÔñʹÓÃComposer¾ÙÐÐ×°Öã¬Ö´ÐÐÏÂÁ

composer create-project –prefer-dist laravel/laravel projectName

ÕâÑù»áÔÚÄ¿½ñĿ¼Ï½¨ÉèÒ»¸öÃûΪprojectNameµÄLaravelÏîÄ¿¡£LaravelÖ§³ÖPHP 7.1»ò¸ü¸ß°æ±¾¡£

¶þ¡¢±àд·ÓÉ

LaravelÖУ¬Â·Óɽç˵ÁËÇëÇóURLÓë´¦Àí³ÌÐòÖ®¼äµÄ¹Øϵ¡£ÎÒÃÇÐèÒªÔÚroutes/web.phpÎļþÖнç˵·ÓÉ¡£

Route::get(‘/api/users’, ‘UserController@index’);

ÉÏÃæµÄ´úÂë½ç˵ÁË/api/usersÕâ¸öÇëÇóURL»á±»Ö¸¶¨µÄ´¦Àí³ÌÐòUserController@index´¦Àí¡£ÕâÀïµÄindexÊÇUserControllerÀàÖеĴ¦ÀíÒªÁ죬ÓÃÓÚ»ñÈ¡Óû§Áбí¡£

Èý¡¢±àд¿ØÖÆÆ÷

ÔÚÉÏÒ»²½ÖÐÎÒÃǽç˵ÁËUserControllerÀ࣬½ÓÏÂÀ´ÐèÒªÔÚapp/Http/ControllersĿ¼Ï½¨ÉèUserController.phpÎļþ£¬²¢ÔÚ¸ÃÎļþÖÐʵÏÖindexÒªÁì¡£

namespace AppHttpControllers;

use IlluminateHttpRequest;

use AppUser;

class UserController extends Controller

{

public function index()
{
    $users = User::all();
    return response()->json($users);
}

µÇ¼ºó¸´ÖÆ

}

ÉÏÃæµÄ´úÂëÖÐÎÒÃÇʹÓÃÁËLaravelÄÚÖõÄÏìÓ¦ÖúÊÖº¯Êýresponse()£¬ÓÃÓÚ½«Ð§¹ûת»»ÎªJSONÃûÌò¢·µ»Øµ½Ç°Ì¨¡£

ËÄ¡¢±àдģ×Ó

ÔÚÉÏÒ»²½ÖÐÎÒÃÇʹÓÃÁËUserÄ£×ÓÀ´»ñÈ¡Óû§Áбí¡£Òò´ËÎÒÃÇ»¹ÐèÒªÔÚappĿ¼Ï½¨ÉèÒ»¸öUser.phpÄ£×ÓÎļþ£¬²¢ÔÚÆäÖнç˵ģ×Ó¡£

namespace App;

use IlluminateDatabaseEloquentModel;

class User extends Model

{

protected $fillable = [
    'name', 'email', 'password',
];

µÇ¼ºó¸´ÖÆ

}

ÉÏÃæµÄ´úÂëÖÐÎÒÃǽç˵ÁËUserÄ£×ÓµÄfillableÊôÐÔ£¬ÓÃÓÚÖ¸¶¨¿ÉÒÔ±»Ìî³äµÄ×ֶΡ£

Îå¡¢²âÊÔ½Ó¿Ú

ÏÖÔÚÎÒÃÇÒѾ­½ç˵ºÃÁË·ÓÉ¡¢¿ØÖÆÆ÷ºÍÄ£×Ó£¬¿ÉÒÔʵÑéʹÓÃRESTful APIÀ´²âÊÔÎÒÃǵĽӿÚ¡£

Æô¶¯LaravelЧÀÍÆ÷

ÔÚÏîÄ¿¸ùĿ¼Ï£¬Ö´ÐÐÒÔÏÂÏÂÁîÆô¶¯LaravelЧÀÍÆ÷£º

php artisan serve

Õ⽫Æô¶¯Ò»¸öWebЧÀÍÆ÷£¬¼àÌý8000¶Ë¿Ú¡£

·¢ËÍHTTPÇëÇó

ʹÓÃPostmanµÈ¹¤¾ß£¬·¢ËÍÇëÇó http://localhost:8000/api/users£¬¼´¿É»ñÈ¡ËùÓÐÓû§µÄJSONÃûÌÃÊý¾Ý¡£

Áù¡¢×ܽá

ͨ¹ýÒÔÉÏ°ì·¨£¬ÎÒÃÇÒѾ­ÀֳɵØʹÓÃLaravel¿ò¼Ü±àдÁËÒ»¸ö¼òÆÓµÄRESTful API½Ó¿Ú¡£ËäÈ»£¬ÔÚÏÖʵ¿ª·¢ÖУ¬ÎÒÃÇ»¹ÐèҪ˼Á¿ÆäËûµÄÒòËØ£¬Èç²ÎÊýУÑé¡¢Çå¾²ÐÔ¡¢»º´æµÈ·½Ãæ¡£¿ÉÊÇÕâÀïÖ»ÊÇÒ»¸ö¼òÆÓµÄʵÀý£¬¿ÉÒÔ×ÊÖúÎÒÃÇ¿ìËÙÉÏÊÖʹÓÃLaravel¿ò¼Ü¿ª·¢Ç°Ì¨½Ó¿Ú¡£

ÒÔÉϾÍÊÇlaravelǰ̨½Ó¿ÚÔõôдµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

13452372176

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

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

QR code
ÍøÕ¾µØͼ