lavarel-数据库迁移及artisan常用命令

视图解析

lavarel前端文件保存为.blade.php类型的文件,解析方法为{{}}
也可以用.php结尾,但是解析时只能用原生方法<?php echo $title;?>

数据库迁移

数据库配置文件在/.env文件中
迁移文件用命令生成,不需要自己写,生成后再补齐内容:
cmd窗口进入项目根目录下,执行创建表命令:

php artisan make:migration create_good_table --create=goods

此时会在/database/migrations文件夹下多多出一个文件,如下:

<?php 
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateGoodsTable extends Migration
{
	/**
	 * Run the migrations.
	 * @return void 
	 * up 函数主要执行添加和修改列的操作
	 * 生成操作
	 */
	public function up()
	{
		Schema::create('goods', function(Blueprint $table){
			$table->increments('id');
			$table->string('name');
			$table->text('content');
			$table->timestamps();
		});
	}

	/**
	 * Reverse the migrations.
	 * @return void
	 * down 函数执行删除操作
	 * 回滚操作
	 */
	public function down(){
		Schema::drop('goods');
	}
}
?>

常见的 artisan 命令

  1. 在版本 5.1.11 新添加,见
http://lavarel-china.org/docs/5.1/5.1/authorization#creating-policies
php artisan make:policy PostPolicy
  1. 针对命令显示帮助信息
php artisan --help OR -h
  1. 抑制输出信息
php artisan --quiet OR -q
  1. 打印lavarel的版本信息
php artisan --version OR -V
  1. 不询问任何交互性的问题
php artisan --no-interaction OR-n
  1. 强制输出 ANSI 格式
php artisan --ansi 
  1. 设置路由缓存
php artisan route:cache
  1. 清除路由缓存
php artisan route:clear

artisan命令创建控制器

php artisan make:controller TestController

备注:在项目根目录下执行,生成文件app/http/controller/TestController

php artisan make:controller Admin\TestController

备注:在项目根目录下执行,生成文件app/http/controller/Admin/TestContoller

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值