定制 kraenkvisuell/entriloquent 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kraenkvisuell/entriloquent

最新稳定版本:v0.5.2

Composer 安装命令:

composer require kraenkvisuell/entriloquent

包简介

无描述信息

README 文档

README

Entriloquent is a Statamic addon that lets you use entries of any collection similar to how you use Laravel models. It is mostly a "convenience" wrapper around "Entry" and mostly makes sense for usage in your PHP/Laravel backend code.

Features

By creating a PHP class extending Kraenkvisuell\Entriloquent you can use this class like a model and have a convenient place for methods concerning this entries of this collection.

How to Install

You can install this addon via Composer:

composer require kraenkvisuell/entriloquent

How to Use

Let's assume you have a Statamic collection called "Products" (having the handle products). Now you can create a PHP class anywhere – I personally use the models directory because that makes sense to me, but it could be anything, like f.e. a "Services" directory.

<?php namespace App\Models; use Kraenkvisuell\Entriloquent\Entriloquent; class Product extends Entriloquent { // you can add any methods here that make sense, like... public function getPriceInclVat() { return $this->price * (1 + ($this->vat / 100)); } }

And use it anywhere in your PHP code like this:

<?php use App\Models\Product; //returns product entry - will ONLY search in products collection: $product = Product::find($id); // also returns product entry, also only searching in products collection: $product = Product::where('slug', 'awesome-product-1')->first(); // or $product = Product::firstWhere('slug', 'awesome-product-1'); // works with any fields on the collection: $product = Product::where('some_custom_field', 'foo bar baz')->first(); // or $product = Product::firstWhere('some_custom_field', 'foo bar baz');

Let's also assume your products collection has a field called price. You can do something like this:

<?php use App\Models\Product; //returns collection of product entries: $products = Product::where('price', '>=', 100);

Important

Entriloquent returns Laravel Collections - this means you don't need to chain a ->get() onto the where() query, it already returns the filtered collection!

create()

You can create entries like this:

<?php use App\Models\Product; $product = Product::create([ 'title' => 'Test Title', 'slug' => 'test-slug', 'price' => 99.99, ]);

all()

You can get all entries like this:

<?php use App\Models\Product; $products = Product::all();

update()

It comes with a convenient way to update your entries, like this:

<?php use App\Models\Product; $product = Product::find($id); $product = $product->update(['title' => 'Updated Title', 'slug' => 'updated-slug']);

Using a custom class name

By default, it looks for a collection that is the snake case plural version of the class name (Product -> products, FooBar -> foo_bars). But you can explicitly define the collection that should be used:

<?php namespace App\Models; use Kraenkvisuell\Entriloquent\Entriloquent; class Post extends Entriloquent { protected static $collectionName = 'blog'; }

统计信息

  • 总下载量: 4.99k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固