laravel使用ORM操作數據庫


laravel使用ORM操作數據庫


public function mode(){

  //查詢所有
$isok=Student::get();



新增、


   (1)  
   $isok=Student::create([
'name'=>'123','pwd'=>'123'

]);

    (2)
$stu=new Student();
$stu->name="123";
$stu->pwd="ww";
$isok= $stu->save();

//修改

$isok= Student::where('pwd','=','56')->update([
'name'=>'123'
]);
刪除

$isok=Student::where('pwd','=','56')->delete();
dd($isok);



}




//模型代碼

namespace App;
use Illuminate\Database\Eloquent\Model;
class Student extends Model{


        指定表明
protected $table='test';
        允許批量賦值的字段
protected $fillable=['name','pwd'];
}
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM