laravelºǫ́ÔõôÉèÖÃ
×÷Ϊһ¿îÊ¢ÐеÄphp¿ò¼Ü£¬laravel×ÔȻҲÊÊÊÊÓÃÀ´¿ª·¢ºǫ́ϵͳ¡£ÔÚʹÓÃlaravel¿ª·¢ºǫ́ϵͳ֮ǰ£¬ÎÒÃÇÐèÒªÏàʶһЩÐëÒªµÄ»ù±¾ÉèÖᣱ¾ÎĽ«Ïò¸÷ÈËÏÈÈÝlaravelºǫ́ϵͳµÄÉèÖÃÒªÁì¡£
×°ÖÃLaravel
ÔÚ×îÏÈLaravelºǫ́ϵͳµÄÉèÖÃ֮ǰ£¬ÎÒÃÇÐèÒªÏÈ×°ÖúÃLaravel¡£ÔÚLaravel¹Ù·½ÍøÕ¾ÉÏ£¬Äã¿ÉÒÔÕÒµ½ÏêϸµÄ×°ÖÃÖ¸µ¼½Ì³Ì¡£×°ÖÃÍêLaravelºó£¬ÎÒÃǾͿÉÒÔ×îÏÈÉèÖÃÁË¡£
ÉèÖÃÊý¾Ý¿â
LaravelʹÓÃÁË.envÉèÖÃÎļþÀ´´æ´¢³ÌÐòËùÐèÒªÓõ½µÄÇéÐαäÁ¿£¬ÆäÖаüÀ¨Êý¾Ý¿âµÄÏà¹ØÐÅÏ¢¡£ÔÚ.envÎļþÖУ¬ÎÒÃÇÐèÒªÉèÖÃÊý¾Ý¿âµÄÀàÐÍ¡¢µØµã¡¢¶Ë¿Ú¡¢Êý¾Ý¿âÃûÒÔ¼°Óû§ÃûºÍÃÜÂëµÈ¡£ÀýÈ磺
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mydatabase
DB_USERNAME=myusername
DB_PASSWORD=mypassword
¿ªÆôLaravelµÄµ÷ÊÔģʽ
ÔÚ¿ª·¢Àú³ÌÖУ¬ÎÒÃÇÐèÒª¾¡¿ÉÄܵط¢Ã÷Ï¢Õù¾ö¹ýʧ¡£Îª´Ë£¬ÎÒÃÇÐèÒª½«LaravelÉèÖÃΪµ÷ÊÔģʽ¡£ÔÚ¿ª·¢ÇéÐÎÖУ¬ÎÒÃÇÖ»ÐèÒª½«.envÎļþÖеÄAPP_DEBUG±äÁ¿ÉèÖÃΪtrue¼´¿É¿ªÆôµ÷ÊÔģʽ£º
APP_DEBUG=true
ÉèÖÃLaravelµÄºǫ́ÖÎÀíϵͳ
Laravel²¢Ã»ÓÐÄÚÖõĺǫ́ÖÎÀíϵͳ£¬¿ÉÊÇÎÒÃÇ¿ÉÒÔʹÓõÚÈý·½µÄ°üÀ´¿ìËÙ¹¹½¨Ò»¸öºǫ́ϵͳ¡£Laravel-adminÊÇÒ»¸öÊ¢Ðеĺǫ́ÖÎÀíϵͳ£¬ËüÌṩÁËÏà¶ÔÍêÕûµÄºǫ́ÖÎÀí¹¦Ð§ºÍÎÞаµÄ×Ô½ç˵ÉèÖá£ÎÒÃÇ¿ÉÒÔͨ¹ýComposer°ü¹ÜÀí¹¤¾ßÀ´×°ÖÃLaravel-admin£º
composer require encore/laravel-admin
×°ÖÃÀֳɺó£¬ÎÒÃÇÐèÒª½«Ð§ÀÍÌṩÕߺÍ×ÊÔ´Îļþ¾ÙÐÐ×¢²á¡£ÔÚconfig/app.phpÎļþÖÐÌí¼ÓÈçÏÂÉèÖãº
‘providers’ => [
// …
EncoreAdminProvidersAdminServiceProvider::class,
],
‘aliases’ => [
// …
‘Admin’ => EncoreAdminFacadesAdmin::class,
],
×îºó£¬ÔÚÏÂÁîÐÐÔËÐÐÒÔÏÂÏÂÁî¼´¿ÉÐû²¼Laravel-adminµÄ×ÊÔ´Îļþ£º
php artisan vendor:publish –provider=”EncoreAdminAdminServiceProvider”
µÇ¼ºÍÉí·ÝÑéÖ¤
µ±ÎÒÃÇ×°ÖÃÁ˺ǫ́ÖÎÀíϵͳºó£¬ÏÂÒ»²½¾ÍÊÇÉèÖõǼºÍÉí·ÝÑéÖ¤¡£ÎÒÃÇ¿ÉÒÔʹÓÃLaravel×Ô´øµÄÉí·ÝÑé֤ϵͳÀ´ÊµÏÖ¡£ÔÚroutes/web.phpÎļþÖÐÌí¼ÓÈçÏ·ÓÉ£º
Auth::routes();
Õâ»á×Ô¶¯ÌìÉúÒ»×éµÇ¼¡¢×¢²áºÍ×¢ÏúµÄ·ÓÉ¡£½ÓÏÂÀ´£¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öusers±íÀ´Öü´æÓû§ÐÅÏ¢£¬ÔÚÏÂÁîÐÐÔËÐÐÒÔÏÂÏÂÁ
php artisan make:model User -m
ҪΪÓû§½¨ÉèÒ»¸öÁУ¬·¿ª¸Õ¸ÕÌìÉúµÄÊý¾Ý¿âǨáãÎļþ£¬Ìí¼ÓÒÔÏ´úÂ룺
Schema::create(‘users’, function (Blueprint $table) {
$table->bigIncrements(‘id’);
$table->string(‘name’);
$table->string(’email’)->unique();
$table->timestamp(’email_verified_at’)->nullable();
$table->string(‘password’);
$table->rememberToken();
$table->timestamps();
});
ÔËÐÐǨáãÏÂÁ½¨Éèusers±í£º
php artisan migrate
ÏÖÔÚÎÒÃǵÄÓû§±íÒѾ׼±¸ºÃÁË¡£ÏÂÒ»²½£¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öÓû§¿ØÖÆÆ÷£¬ÓÃÓÚÖÎÀíºǫ́Óû§ÐÅÏ¢¡£ÔËÐÐÒÔÏÂÏÂÁ
php artisan make:controller UserController
ÔÚUserControllerÖУ¬ÎÒÃÇÐèÒª½ç˵Óû§ÖÎÀíµÄһЩҪÁ죺
class UserController extends Controller
{
public function index()
{
// TODO: ÏÔʾÓû§Áбí
µÇ¼ºó¸´ÖÆ
}
public function create()
{
// TODO: ½¨ÉèÓû§
µÇ¼ºó¸´ÖÆ
}
public function store(Request $request)
{
// TODO: ÉúÑÄÓû§ÐÅÏ¢
µÇ¼ºó¸´ÖÆ
}
public function edit($id)
{
// TODO: ÏÔʾ±à¼Óû§Ò³Ãæ
µÇ¼ºó¸´ÖÆ
}
public function update(Request $request, $id)
{
// TODO: ¸üÐÂÓû§ÐÅÏ¢
µÇ¼ºó¸´ÖÆ
}
public function destroy($id)
{
// TODO: ɾ³ýÓû§
µÇ¼ºó¸´ÖÆ
}
}
×îºó£¬ÔÚroutes/web.phpÎļþÖÐÌí¼ÓÈçÏ´úÂ룬½«Óû§ÖÎÀíÏà¹ØµÄ·ÓÉ×¢²áµ½ÏµÍ³ÖУº
Route::resource(‘users’, ‘UserController’);
ÏÖÔÚ£¬ÎÒÃÇÒѾÍê³ÉÁËLaravelºǫ́ϵͳµÄÉèÖá£Í¨¹ýLaravel-admin£¬ÎÒÃÇ¿ÉÒÔ¿ìËÙ¹¹½¨Ò»¸ö¹¦Ð§ÍêÕûµÄºǫ́ÖÎÀíϵͳ£¬²¢ÇÒͨ¹ýLaravelµÄÇ¿Ê¢¹¦Ð§£¬ÎÒÃÇ¿ÉÒÔÇáËÉʵÏÖÊý¾ÝµÄÔöɾ¸Ä²é¡¢±íµ¥ÑéÖ¤¡¢ÎļþÉÏ´«µÈ¹¦Ð§¡£ÈôÊÇÄ㻹ÏëÉîÈëѧϰLaravelºǫ́ϵͳµÄ¿ª·¢£¬¿ÉÒÔ¼ÌÐø̽Ë÷Ïà¹ØµÄÎĵµºÍ½Ì³Ì¡£
ÒÔÉϾÍÊÇlaravelºǫ́ÔõôÉèÖõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡