rinvex / laravel-testimonials
Rinvex Testimonials 是一个多态的 Laravel 软件包,用于管理推荐语。客户可以给您提供推荐语,您可以单独批准或拒绝每一个。推荐语有助于展示您的服务从客户那里获得的热情和喜爱,鼓励其他人加入热潮!
Requires
- php: ^7.4.0 || ^8.0.0
- illuminate/console: ^8.0.0 || ^9.0.0
- illuminate/database: ^8.0.0 || ^9.0.0
- illuminate/support: ^8.0.0 || ^9.0.0
- rinvex/laravel-support: ^5.0.0
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.30.0
- illuminate/container: ^8.0.0 || ^9.0.0
- phpunit/phpunit: ^9.5.0
README
⚠️ 此软件包已废弃,不再维护。未建议替代软件包。⚠️
👉 如果您有兴趣成为此软件包的主要维护者,请 联系我!
Rinvex Testimonials 是一个多态的 Laravel 软件包,用于管理推荐语。客户可以给您提供推荐语,您可以单独批准或拒绝每一个。推荐语有助于展示您的服务从客户那里获得的热情和喜爱,鼓励其他人加入热潮!
安装
-
通过 composer 安装软件包
composer require rinvex/laravel-testimonials
-
发布资源(迁移和配置文件)
php artisan rinvex:publish:testimonials
-
使用以下命令执行迁移
php artisan rinvex:migrate:testimonials
-
完成!
使用方法
在查看代码示例之前,我们需要明确此软件包背后的概念及其工作原理。 Rinvex Testimonials 假设每个推荐语有两个关系,即提供推荐语的主体 (称为attestant),第二个是接收推荐语的主体 (称为subject)。这些主体可以是任何东西,每个推荐语都存储了 type
和 id
(两者形成一个多态关系)用于 subject 和 attestant。实体可以提供推荐语、接收推荐语或两者兼具。这取决于您自己决定。
将提供推荐语的功能添加到您的模型中
要为模型添加支持提供推荐语的功能,只需使用 \Rinvex\Testimonials\Traits\GivesTestimonials
特性
namespace App\Models; use Illuminate\Database\Eloquent\Model; use Rinvex\Testimonials\Traits\GivesTestimonials; class User extends Model { use GivesTestimonials; }
将接收推荐语的功能添加到您的模型中
要为模型添加支持接收推荐语的功能,只需使用 \Rinvex\Testimonials\Traits\TakesTestimonials
特性
namespace App\Models; use Illuminate\Database\Eloquent\Model; use Rinvex\Testimonials\Traits\TakesTestimonials; class Company extends Model { use TakesTestimonials; }
这两个特性可以用于同一模型而不会出现任何问题。
创建新的推荐语
创建新的推荐语非常简单,可以通过多种方式完成,使用适合您上下文的方式。让我们看看如何做到这一点
$user = \App\Models\User::find(1); $company = \App\Models\Company::find(1); $testimonial = app('rinvex.testimonials.testimonial'); $testimonialBody = 'I have been using this service as my main learning resource since it went live. I believe it has the best teaching material out there.'; // Create a new testimonial via subject model (attestant, body) $company->newTestimonial($user, $testimonialBody); // Create a new testimonial via attestant model (subject, body) $user->newTestimonial($company, $testimonialBody); // Create a new testimonial explicitly $testimonial->make(['body' => $testimonialBody]) ->subject()->associate($company) ->attestant()->associate($user) ->save();
查询推荐语模型
您可以通过以下方式获取有关特定推荐语更多详细信息
$testimonial = app('rinvex.testimonials.testimonial')->find(1); $company = $testimonial->subject; // Get the owning company model $user = $testimonial->attestant; // Get the owning user model $testimonialsOfCompany = app('rinvex.testimonials.testimonial')->ofSubject($company)->get(); // Get testimonials of the given company $recommendationsOfUser = app('rinvex.testimonials.testimonial')->ofAttestant($user)->get(); // Get testimonials of the given user $company->testimonialsOf($user)->get(); // Get testimonials of the given user $user->recommendationsOf($company)->get(); // Get testimonials by the user for the given company $user->recommendations; // Get given testimonials collection $user->recommendations(); // Get given testimonials query builder $company->testimonials; // Get received testimonials collection $company->testimonials(); // Get received testimonials query builder
不出所料,\Rinvex\Testimonials\Models\Testimonial
模型本身扩展了 Eloquent,因此您可以像通常一样流畅地管理它。
变更日志
请参阅变更日志以获取项目的完整历史。
支持
以下支持渠道尽在您的指尖
贡献 & 协议
感谢您考虑为这个项目做出贡献!贡献指南可以在CONTRIBUTING.md中找到。
欢迎提出错误报告、功能请求和拉取请求。
安全漏洞
如果您在这个项目中发现了安全漏洞,请发送电子邮件至help@rinvex.com。所有安全漏洞都将得到及时处理。
关于Rinvex
Rinvex是一家成立于2016年6月的埃及亚历山大市的软件解决方案初创公司,专注于为中小企业提供集成企业解决方案。我们相信,我们的动力在于价值、影响力和影响力,这是我们与众不同的地方,通过软件的力量释放我们哲学的无限可能性。我们喜欢称之为“生活速度的创新”。这就是我们如何为推进人类文明贡献我们的力量。
许可
本软件基于MIT许可(MIT)发布。
(c) 2016-2021 Rinvex LLC,部分权利保留。