Eloquent ORM
Nguyn Hu Th
PHÁT TRIỂN PHẦN MỀM NGUN M
Eloquent
Introduction
Defining Models
Retrieving Models
Inserting & Updating Models
Inserts
Updates
Deleting Models
Soft Deleting
2
Eloquent
Cung cấp một API ActiveRecord đơn giản tuyệt
vời khi làm việc với database.
Mỗi database table sẽ một "Model"tương ứng để tương
tác với table đó.
Model cho phép bạn query dữ liệu trong table, cũng như
chèn thêm các dữ liệu mới.
3
Định nghĩa Models
Model nằm trong thư mục app/, thể tuỳ chỉnh trong file
composer.json.
Kế thừa từ class Illuminate\Database\Eloquent\Model.
Câu lệnh một model tên Flight:
php artisan make:model Flight
Nếu muốn tạo database migration đi kèm với model thì sử
dụng them cờ --migration hoặc -m:
php artisan make:model Flight migration
Hoặc
php artisan make:model Flight -m
4
Eloquent Model: Cấu trúc class
5
namespace App;
use Illuminate\Database\Eloquent\Model;
class Flight extends Model
{
//
}