composer create-project laravel/laravel learnlaravel5然后,稍等片刻,当前目录下就会出现一个叫 learnlaravel5 的文件夹。 然后将网站根目录配置为 learnlaravel5/public。 如果你不会配置,建议去学会配置,网上资料很多。如果自暴自弃,可以把 的第 29 行'url' => '[url=http://localhost]http://localhost[/url]', 配置成你的子目录地址,注意,要一直配置到 ***/learnlaravel5/public。 使用浏览器访问你配置的地址,将看到以下画面(我在本地配置的地址为 [url=http://fuck.io:88]http://fuck.io:88[/url] ): [img]http://files.jb51.net/file_images/article/201504/201504090933561.jpg[/img] [b]2. 体验 Auth 系统并完成安装[/b] —— 经过上面的过程,Laravel 5 的安装成功了? —— 没有o(╯□╰)o 查看路由文件 `learnlaravel5/app/Http/routes.php` 的代码:
Route::get('/', 'WelcomeController@index');
Route::get('home', 'HomeController@index');
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
cd learnlaravel5 sudo chmod -R 777 storage
DB_HOST=localhost DB_DATABASE=laravel5 DB_USERNAME=root DB_PASSWORD=password
php artisan migrate得到的结果如下: [img]http://files.jb51.net/file_images/article/201504/201504090933565.jpg[/img] 如果你运行命令报错,请检查数据库连接设置。 至此,数据库迁移已完成,你可以打开 [url=http://fuck.io:88/home]http://fuck.io:88/home[/url] 欢快地尝试注册、登录啦。 [b]4. 模型 Models[/b] 接下来我们将接触Laravel最为强大的部分,Eloquent ORM,真正提高生产力的地方,借用库克的一句话:鹅妹子英! 运行一下命令:
php artisan make:model Article php artisan make:model Page
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();
});
php artisan migrate成功以后, tables 表和 pages 表已经出现在了数据库里,去看看吧~ [b]5. 数据库填充 Seeder[/b] 在 `learnlaravel5/database/seeds/` 下新建 `PageTableSeeder.php` 文件,内容如下:
<?php
use Illuminate\Database\Seeder;
use App\Page;
class PageTableSeeder extends Seeder {
public function run()
{
DB::table('pages')->delete();
for ($i=0; $i < 10; $i++) {
Page::create([
'title' => 'Title '.$i,
'slug' => 'first-page',
'body' => 'Body '.$i,
'user_id' => 1,
]);
}
}
}
// $this->call('UserTableSeeder');
这一句为
$this->call('PageTableSeeder');
然后运行命令进行数据填充:
composer dump-autoloadphp artisan db:seed去看看 pages 表,是不是多了十行数据? 本教程示例代码见:[url=https://github.com/johnlui/Learn-Laravel-5]https://github.com/johnlui/Learn-Laravel-5[/url] 大家在任何地方卡住,最快捷的解决方式就是去看我的示例代码。 以上所述就是本文的全部内容了,希望能够对大家学习Laravel5框架有所帮助。
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有