标签:compose cti 框架 price orm chunk public 安全 count
class Flight extends Model { /** * 与模型关联的数据表。 */ protected $table = ‘my_flights‘;
/** * 指定主键。 */ public $primaryKey = ‘id‘;
/** * 指定是否模型应该被戳记时间。 */ public $timestamps = false;
/** * 模型的日期字段保存格式。 */ protected $dateFormat = ‘U‘; /** * 此模型的连接名称。 */ protected $connection = ‘connection-name‘; }
//首先创建一个新模型实例 $flight = new Flight; //给这个模型添加属性 $flight->name = $name; $flight->length = $length; //... 其它更多属性 $flight->save();
$flight = Flight ::create(Input::all());
$input = [ ‘name‘=>‘test‘, ‘content‘=>‘testflight‘, ‘length‘=>2000, // ‘price‘=>1880, 即使这里写了价格,因为是受保护的,调用下面的create,也不会插入成功
]; $flight = Flight ::create($input); //如果想成功,那么就重新定义一下属性,然后调用save方法 $flight ->price= 200; $flight ->save();
$flight = App\Flight::firstOrCreate([‘name‘ => ‘Flight 10‘]);
$flight = App\Flight::firstOrNew([‘name‘ => ‘Flight 10‘]); $flight->save(); //存入到数据库
$flight = App\Flight::find(1); //先从是数据库中取回数据 $flight->delete(); //实现删除
App\Flight::destroy(1); App\Flight::destroy([1, 2, 3]); App\Flight::destroy(1, 2, 3);
$deletedRows = App\Flight::where(‘active‘, 0)->delete();
$flight = App\Flight::find(1); $flight->name = ‘New Flight Name‘; $flight->save();
App\Flight::where(‘active‘, 1) ->where(‘destination‘, ‘San Diego‘) ->update([‘delayed‘ => 1]);
$flights = Flight::all();
$flights = App\Flight::where(‘active‘, 1) ->orderBy(‘name‘, ‘desc‘) ->take(10) ->get();
Flight::chunk(200, function ($flights) {
foreach ($flights as $flight) {
//
}
});
$flight = App\Flight::find(1); // 通过主键取回一个模型... $flight = App\Flight::where(‘active‘, 1)->first(); // 取回符合查找限制的第一个模型 ... $model = App\Flight::findOrFail(1); //找不到模型时抛出一个异常 $model = App\Flight::where(‘legs‘, ‘>‘, 100)->firstOrFail();
$count = App\Flight::where(‘active‘, 1)->count();
$max = App\Flight::where(‘active‘, 1)->max(‘price‘);
标签:compose cti 框架 price orm chunk public 安全 count
原文地址:http://www.cnblogs.com/redirect/p/6136014.html