修改配置:./app/config/databases.php中修改mysql的配置php
'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'laravel', 'username' => 'root', 'password' => 'password', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => 'cms_',/*表前綴*/ ),
2. 使用命令建立表:mysql
php artisan migrate --package=cartalyst/sentry /*建立5張sentry本身的表*/
3.權限系統數據庫配置laravel
'Cartalyst\Sentry\SentryServiceProvider',在./app/config/app.php中'providers' => array(增長 'Sentry' => 'Cartalyst\Sentry\Facades\Laravel\Sentry',在./app/config/app.php中'aliases' => array(增長
4.運行命令建立2個數據庫遷移文件(有點相似於yii中的migrate的意思)sql
php artisan migrate:make create_articles_table --create=articles php artisan migrate:make create_pages_table --create=pages
5.編輯生成的./app/databases/migrations/文件數據庫
Schema::create('articles', function(Blueprint $table) { $table->increments('id'); $table->string('title'); $table->string('slug')->nullable(); $table->text('body')->nullable(); $table->string('image')->nullable(); $table->integer('user_id'); $table->timestamps(); }); Schema::create('pages', function(Blueprint $table) { $table->increments('id'); $table->string('title'); $table->string('slug')->nullable(); $table->text('body')->nullable(); $table->integer('user_id'); $table->timestamps(); });
6.建立表(表創建完成啦)app
php artisan migrate /*真心好像yii的 migdate*/
7.建立模型yii
php artisan generate:model article php artisan generate:model page 這個時候就在app/model下出現倆個模型類
8.插入數據ide
php artisan generate:seed page php artisab generate:seed article 這個時候就在./app/config/seeds下出現2個文件 分別更改着2個文件 /*循環插入10條*/ /*PageTableSeeder.php*/ foreach(range(1, 10) as $index) { Page::create([ 'title' => $faker->sentence($nbWords = 6), 'slug' => 'first-page', 'body' => $faker->paragraph($nbSentences = 5), 'user_id' => 1, ]); } /*ArticleTableSeeder.php*/ foreach(range(1, 10) as $index) { Article::create([ 'title' => $faker->sentence($nbWords = 6), 'slug' => 'first-post', 'body' => $faker->paragraph($nbSentences = 5), 'user_id' => 1, ]); } 而後在databaseSeeder.php增長2行 $this->call('ArticleTableSeeder'); $this->call('PageTableSeeder'); 執行 php artisan db:send 這樣就插入10條數據到2張表中