标签:protect er模型 rem eloquent 删除 class set ima incr
1 CREATE TABLE `user` ( 2 `id` int(11) NOT NULL AUTO_INCREMENT, 3 `username` varchar(255) NOT NULL, 4 `password` varchar(255) NOT NULL, 5 `created_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, 6 `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, 7 PRIMARY KEY (`id`) 8 ) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Route::group([‘prefix‘=>‘user‘],function (){ Route::get(‘/add‘,‘UserController@add‘);//添加 Route::get(‘/delete‘,‘UserController@delete‘);//删除 Route::get(‘/update‘,‘UserController@update‘);//修改 Route::get(‘/query‘,‘UserController@query‘);//查询 });
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class User extends Model { //添加表名 protected $table = ‘user‘; //设置之后允许用户批量操作 protected $fillable = [‘username‘, ‘password‘]; //禁用时间戳 public $timestamps = false; }
<?php namespace App\Http\Controllers; use App\Models\User; use Illuminate\Http\Request; class UserController extends Controller { //orm添加方法 public function add() { $data = User::create([‘username‘ => ‘胡歌‘, ‘password‘ => ‘222‘]); return dd($data); } //删除方法 public function delete() { $data = User::find(13)->delete(); return dd($data); } //修改方法 public function update() { $data = User::where([‘id‘ => ‘10‘])->update([‘username‘ => ‘实验‘]); return dd($data); } //查询方法 public function query() { $data = User::all(); return dd($data); } }
标签:protect er模型 rem eloquent 删除 class set ima incr
原文地址:https://www.cnblogs.com/yaoliuyang/p/12335607.html