标签:fun 数据库 arch 名称 min laravel框架 ODB 查询 new
CREATE TABLE `user` ( `id` int(5) NOT NULL AUTO_INCREMENT, `username` varchar(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, `password` varchar(999) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Route::get(‘demo‘,‘DemoController@demo‘);
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class User extends Model { // protected $table=‘user‘;//对应表名 protected $fillable=[‘id‘,‘username‘,‘password‘];//创建数据库对应字段 public $timestamps=false;//禁用时间戳 }
<?php namespace App\Http\Controllers; use App\Models\User; class DemoController extends Controller { // public function demo() { $data = new User();//实例化模型 $data->username = ‘胡歌‘;//给名称字段赋值 $data->password = md5(‘222‘);//给密码字段赋值 $data->save();//保存信息 } }
6.1更新
$data=User::find(‘3‘);//直接查询id $data->username = ‘ss‘; $data->password = md5(‘222‘); $data->save();//使用save()方法自动维护
laravel框架orm中实例化model-save()方法的使用
标签:fun 数据库 arch 名称 min laravel框架 ODB 查询 new
原文地址:https://www.cnblogs.com/yaoliuyang/p/12538988.html