search
HomePHP FrameworkThinkPHPIntroducing a useful ThinkPHP Repository package

Introduction

think-repository is a repository provided for thinkphp 6.0.* for abstract data layer, Make our applications more flexible for maintenance.

You know

ThinkPHP

>= thinkphp 6.0.*

composer require fanxd/think-repository dev-master

Best

Use

##commands
## under multi-application #php think fanxd:repository Post

##Route

Route::resource('post', 'PostController');

Available methods
get() // Find a record
  • paginate() // Pagination query
  • create($data) //Write data
  • save($data) //Save the current data object
  • delete( $where) // Delete record
  • update($where,$data) // Update record
  • find($id) // Find a single record and throw an exception if it does not exist
  • findWhere($where,$columns = ['*']) // Specify AND query conditions to find a single record
  • with([]) //Related query
  • search( []) //Data search
  • order($order) //Sort
  • Find records

Paging query

Find by result by id
$posts=$this->repository->first($id);

##Load model relationship

$posts=$this->repository->with(['state'])->find($id);

Press Results are found by field name

$posts=$this->repository->findByField('title', 'Hello');

Find by multiple fields

$posts=$this->repository->findWhere([ 'id' => 1], ['id', 'title]);


Find multiple values ​​in one field by result

$posts=$this->repository-> ;findWhereIn('id', [1,2,3,4,5]);

Find by results by excluding multiple values ​​in a field

$posts=$this->repository->findWhereNotIn('id', [6,7,8,9,10]);

Write data

$post = $this->repository->create($data);

Update record

$posts=$this->repository->update($where, $data);

##Delete record

$this->repository->delete($id)

Delete entries in the repository by multiple fields

$this->repository->deleteWhere([

'id' => 1, 'user_id' => 1])

Transformer

The system will automatically generate the
transform

file. You can choose whether to enable it. The main function for me is to beautify the interface and make us more professional:)
<?php namespace app\api\transform;use fanxd\repository\command\transform\Transform;class PostTransform extends Transform{
    public function transform($items)
    {
        return [
            &#39;id&#39;            => $items['id'],
            //... 
            'createTime'    => $items['create_time'],
            'updateTime'    => $items['update_time']
        ];
    }}

More methods will be added one after another. If you have good ideas, please tell me and I will update them in seconds!!!

Related recommendations: The latest 10 thinkphp video tutorials

The above is the detailed content of Introducing a useful ThinkPHP Repository package. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:learnku. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool