Laravel ORM 常用 Demo

select + where + with + orderBy + paginate

    Post::select('title', 'id')
            ->where('user_id',$user->id)
            ->orWhere('name', 'LIKE', '%' . $name . '%')
            ->orderBy('updated_at', 'desc')
            ->with('user')
            ->paginate(20);

注意

1. order 是用orderBy,
2. select 很重要,不填就是相當於select *
3. with是 many to many, one to one, one to many 那種關系
4. 兩次where() 意思就是 and