Laravel框架学习笔记(二)项目实战之模型(Mod
网络编程 2021-07-05 09:50www.168986.cn编程入门
上一篇已经介绍开发环境的搭建,这篇将从项目实战开发,一步一步了解laravel框架。我们来了解下laravel框架的模型
(Models)
在开发mvc项目时,models都是第一步。
狼蚁网站SEO优化就从建模开始。
1.实体关系图,
由于不知道php有什么好的建模工具,这里我用的vs ado.实体模型数据建模
狼蚁网站SEO优化开始laravel编码,编码之前得配置数据库连接,在app/config/database.php文件
'mysql' => array( 'driver' => 'mysql', 'read' => array( 'host' => '127.0.0.1:3306', ), 'write' => array( 'host' => '127.0.0.1:3306' ), 'database' => 'test', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ),
配置好之后,需要用到artisan工具,这是一个php命令工具在laravel目录中
需要要通过artisan建立一个迁移 migrate ,这点和asp. mvc几乎是一模一样
在laravel目录中 shfit+右键打开命令窗口 输入artisan migrate:make create_XXXX会在app/database/migrations文件下生成一个带时间戳前缀的迁移文件
代码
<?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateTablenameTable extends Migration { / Run the migrations. @return void / public function up() { } / Reverse the migrations. @return void / public function down() { } }
看到这里有entityframework 迁移经验的基本上发现这是出奇的相似啊。
接下来就是创建我们的实体结构,laravel 的结构生成器可以参考http://v4.golaravel./docs/4.1/schema
<?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateTablenameTable extends Migration { / Run the migrations. @return void / public function up() { Schema::create('posts', function(Blueprint $table) { $table->increments('id'); $table->unsignedInteger('user_id'); $table->string('title'); $table->string('read_more'); $table->text('content'); $table->unsignedInteger('ment_count'); $table->timestamps(); }); Schema::create('ments', function(Blueprint $table) { $table->increments('id'); $table->unsignedInteger('post_id'); $table->string('menter'); $table->string('email'); $table->text('ment'); $table->boolean('approved'); $table->timestamps(); }); Schema::table('users', function (Blueprint $table) { $table->create(); $table->increments('id'); $table->string('username'); $table->string('password'); $table->string('email'); $table->string('remember_token', 100)->nullable(); $table->timestamps(); }); } / Reverse the migrations. @return void / public function down() { Schema::drop('posts'); Schema::drop('ments'); Schema::drop('users'); } }
继续在上面的命令窗口输入php artisan migrate 将执行迁移
更多迁移相关知识http://v4.golaravel./docs/4.1/migrations
先写到这里明天继续
上一篇:跟我学Laravel之快速入门
下一篇:Laravel框架学习笔记(一)环境搭建
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指