比如我有一个imgs表,现在在这个表中添加一个votes字段
php artisan make:migration add_votes_to_imgs_table --table=imgs
然后修改生成的migration文件
public function up()
{
Schema::table('imgs', function (Blueprint $table) {
$table->integer('votes');
});
}
最后php artisan migrate
如果直接改table的话,就不用以上几步了,然后可以直接修改对应的model
laravel文档中还有一种不修改表的方法
Attribute Casting
The $casts
property on your model provides a convenient method of converting attributes to common data types. The $casts
property should be an array where the key is the name of the attribute being cast, while the value is the type you wish to cast the column to. The supported cast types are: integer
, real
, float
, double
, string
, boolean
, object
, array
, collection
, date
, datetime
, and timestamp
.
For example, let's cast the is_admin
attribute, which is stored in our database as an integer (0
or1
) to a boolean value:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [
'is_admin' => 'boolean',
];
}
Now the is_admin
attribute will always be cast to a boolean when you access it, even if the underlying value is stored in the database as an integer:
$user = App\User::find(1);
if ($user->is_admin) {
//
}
相关推荐
Laravel 5.2 中文文档.CHM
01.Laravel5.2开发的博客项目视频教程介绍.zip 02.Laravel 5.2 框架简介.zip 03.Laravel5.2类库管理神器Composer安装和配置.zip 04.Laravel5.2一键安装包安装及初始化配置.zip 05.Laravel5.2参考文档及起步说明....
PHP基于Laravel 5.2开发的Git管理系统 PHP基于Laravel 5.2开发的Git管理系统 PHP基于Laravel 5.2开发的Git管理系统 PHP基于Laravel 5.2开发的Git管理系统 PHP基于Laravel 5.2开发的Git管理系统 PHP基于Laravel ...
Laravel 5.2 中文文档(Laravel学院提供)
laravel5.2 课程讲义 pdf
Laravel 5.2 在 5.1 基础上继续改进和优化,添加了许多新的功能特性:多认证驱动支持、隐式模型绑定、简化 Eloquent 全局作用域、可选择的认证脚手架、中间件组、访问频率限制、数组输入验证优化等等。
Laravel5.2博客项目实战开发视频教程 演示代码
Laravel 5.2参考手册
应该是网络上最容易理解的laravel教程了。
Laravel5.2参考手册-中文CHM版.CHM
laravel-5.2.31
laravel5.2一键安装包
最新Laravel5.2、5.1中文手册集合包
基于Laravel5.2和adminLTE通用模版开发的一个报名系统.zip
dropzone-laravel-image-upload, Laravel 5.2和 Dropzone.js 自动图像上传,带有删除链接 Laravel 5.2和 Dropzone.js 自动图像上传,带有删除链接这个项目与来自 Codingo Tuts的教程相关。这里项目中包含的内容包括...
laravel-apz, 从a 到z 构建 Laravel 5.2应用的指南 :从a 到z的指南,从a 到z 构建 Laravel 5.2应用。 教程( 从这里开始)https://github.com/jp7internet/laravel-apz/wiki视频屏幕https://www.you
Laravel开发-laravel-5.2-ddd Laravel 5.2滴滴涕。
管理系统系列--基于laravel5.2的后台管理系统
学习laravel时跟着视频写的。
首先可以参考我的博客怎么去使用uploadifive(h5),==...PHP我基于laravel5.2开发博客发现flash上传已经不行了,于是找到H5的,并 用于在laravel5.2框架,给大家分享一下免费的下载(好像最低1积分,不能开 发免费)。