├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── composer.json ├── config └── config.php ├── database └── migrations │ └── 2020_01_01_000001_create_testimonials_table.php ├── phpstan.neon.dist └── src ├── Console └── Commands │ ├── MigrateCommand.php │ ├── PublishCommand.php │ └── RollbackCommand.php ├── Models └── Testimonial.php ├── Providers └── TestimonialsServiceProvider.php └── Traits ├── GivesTestimonials.php └── TakesTestimonials.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Rinvex Testimonials Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | This project adheres to [Semantic Versioning](CONTRIBUTING.md). 6 | 7 | 8 | ## [v5.0.1] - 2020-12-25 9 | - Add support for PHP v8 10 | 11 | ## [v5.0.0] - 2020-12-22 12 | - Upgrade to Laravel v8 13 | - Move custom eloquent model events to module layer from core package layer 14 | - Refactor and tweak Eloquent Events 15 | 16 | ## [v4.1.0] - 2020-06-15 17 | - Fix attaching categories by their IDs where IDs are passed mistakenly as strings in some cases! 18 | - Fix phone validation rule 19 | - Drop using rinvex/laravel-cacheable from core packages for more flexibility 20 | - Caching should be handled on the application layer, not enforced from the core packages 21 | - Drop PHP 7.2 & 7.3 support from travis 22 | 23 | ## [v4.0.6] - 2020-05-30 24 | - Remove default indent size config 25 | - Add strip_tags validation rule to string fields 26 | - Specify events queue 27 | - Explicitly specify relationship attributes 28 | - Add strip_tags validation rule 29 | - Explicitly define relationship name 30 | 31 | ## [v4.0.5] - 2020-04-12 32 | - Fix ServiceProvider registerCommands method compatibility 33 | 34 | ## [v4.0.4] - 2020-04-09 35 | - Tweak artisan command registration 36 | - Reverse commit "Convert database int fields into bigInteger" 37 | - Refactor publish command and allow multiple resource values 38 | 39 | ## [v4.0.3] - 2020-04-04 40 | - Fix namespace issue 41 | 42 | ## [v4.0.2] - 2020-04-04 43 | - Enforce consistent artisan command tag namespacing 44 | - Enforce consistent package namespace 45 | - Drop laravel/helpers usage as it's no longer used 46 | 47 | ## [v4.0.1] - 2020-03-20 48 | - Convert into bigInteger database fields 49 | - Add shortcut -f (force) for artisan publish commands 50 | - Fix migrations path 51 | 52 | ## [v4.0.0] - 2020-03-15 53 | - Upgrade to Laravel v7.1.x & PHP v7.4.x 54 | 55 | ## [v3.0.2] - 2020-03-13 56 | - Tweak TravisCI config 57 | - Add migrations autoload option to the package 58 | - Tweak service provider `publishesResources` 59 | - Remove indirect composer dependency 60 | - Update StyleCI config 61 | 62 | ## [v3.0.1] - 2019-12-18 63 | - Fix `migrate:reset` args as it doesn't accept --step 64 | - Create event classes and map them in the model 65 | 66 | ## [v3.0.0] - 2019-09-23 67 | - Upgrade to Laravel v6 and update dependencies 68 | 69 | ## [v2.1.1] - 2019-06-03 70 | - Enforce latest composer package versions 71 | 72 | ## [v2.1.0] - 2019-06-02 73 | - Update composer deps 74 | - Drop PHP 7.1 travis test 75 | - Refactor migrations and artisan commands, and tweak service provider publishes functionality 76 | 77 | ## [v2.0.0] - 2019-03-03 78 | - Rename environment variable QUEUE_DRIVER to QUEUE_CONNECTION 79 | - Require PHP 7.2 & Laravel 5.8 80 | - Apply PHPUnit 8 updates 81 | 82 | ## [v1.0.1] - 2018-12-22 83 | - Update composer dependencies 84 | - Add PHP 7.3 support to travis 85 | 86 | ## [v1.0.0] - 2018-10-01 87 | - Enforce Consistency 88 | - Support Laravel 5.7+ 89 | - Rename package to rinvex/laravel-testimonials 90 | 91 | ## [v0.0.3] - 2018-09-21 92 | - Update travis php versions 93 | - Define polymorphic relationship parameters explicitly 94 | - Drop StyleCI multi-language support (paid feature now!) 95 | - Update composer dependencies 96 | - Prepare and tweak testing configuration 97 | - Highlight variables in strings explicitly 98 | - Update StyleCI options 99 | - Update PHPUnit options 100 | - Add testimonial model factory 101 | 102 | ## [v0.0.2] - 2018-02-18 103 | - Update PHPUnit to 7.0.0 104 | - Update composer packages 105 | - Drop Laravel 5.5 support 106 | 107 | ## v0.0.1 - 2018-02-17 108 | - Tag first release 109 | 110 | [v5.0.1]: https://github.com/rinvex/laravel-testimonials/compare/v5.0.0...v5.0.1 111 | [v5.0.0]: https://github.com/rinvex/laravel-testimonials/compare/v4.1.0...v5.0.0 112 | [v4.1.0]: https://github.com/rinvex/laravel-testimonials/compare/v4.0.6...v4.1.0 113 | [v4.0.6]: https://github.com/rinvex/laravel-testimonials/compare/v4.0.5...v4.0.6 114 | [v4.0.5]: https://github.com/rinvex/laravel-testimonials/compare/v4.0.4...v4.0.5 115 | [v4.0.4]: https://github.com/rinvex/laravel-testimonials/compare/v4.0.3...v4.0.4 116 | [v4.0.3]: https://github.com/rinvex/laravel-testimonials/compare/v4.0.2...v4.0.3 117 | [v4.0.2]: https://github.com/rinvex/laravel-testimonials/compare/v4.0.1...v4.0.2 118 | [v4.0.1]: https://github.com/rinvex/laravel-testimonials/compare/v4.0.0...v4.0.1 119 | [v4.0.0]: https://github.com/rinvex/laravel-testimonials/compare/v3.0.2...v4.0.0 120 | [v3.0.2]: https://github.com/rinvex/laravel-testimonials/compare/v3.0.1...v3.0.2 121 | [v3.0.1]: https://github.com/rinvex/laravel-testimonials/compare/v3.0.0...v3.0.1 122 | [v3.0.0]: https://github.com/rinvex/laravel-testimonials/compare/v2.1.1...v3.0.0 123 | [v2.1.1]: https://github.com/rinvex/laravel-testimonials/compare/v2.1.0...v2.1.1 124 | [v2.1.0]: https://github.com/rinvex/laravel-testimonials/compare/v2.0.0...v2.1.0 125 | [v2.0.0]: https://github.com/rinvex/laravel-testimonials/compare/v1.0.1...v2.0.0 126 | [v1.0.1]: https://github.com/rinvex/laravel-testimonials/compare/v1.0.0...v1.0.1 127 | [v1.0.0]: https://github.com/rinvex/laravel-testimonials/compare/v0.0.3...v1.0.0 128 | [v0.0.3]: https://github.com/rinvex/laravel-testimonials/compare/v0.0.2...v0.0.3 129 | [v0.0.2]: https://github.com/rinvex/laravel-testimonials/compare/v0.0.1...v0.0.2 130 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [help@rinvex.com](mailto:help@rinvex.com). All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guide 2 | 3 | This project adheres to the following standards and practices. 4 | 5 | 6 | ## Versioning 7 | 8 | This project is versioned under the [Semantic Versioning](http://semver.org/) guidelines as much as possible. 9 | 10 | Releases will be numbered with the following format: 11 | 12 | - `..` 13 | - `..` 14 | 15 | And constructed with the following guidelines: 16 | 17 | - Breaking backward compatibility bumps the major and resets the minor and patch. 18 | - New additions without breaking backward compatibility bump the minor and reset the patch. 19 | - Bug fixes and misc changes bump the patch. 20 | 21 | 22 | ## Pull Requests 23 | 24 | The pull request process differs for new features and bugs. 25 | 26 | Pull requests for bugs may be sent without creating any proposal issue. If you believe that you know of a solution for a bug that has been filed, please leave a comment detailing your proposed fix or create a pull request with the fix mentioning that issue id. 27 | 28 | 29 | ## Coding Standards 30 | 31 | This project follows the FIG PHP Standards Recommendations compliant with the [PSR-1: Basic Coding Standard](http://www.php-fig.org/psr/psr-1/), [PSR-2: Coding Style Guide](http://www.php-fig.org/psr/psr-2/) and [PSR-4: Autoloader](http://www.php-fig.org/psr/psr-4/) to ensure a high level of interoperability between shared PHP code. If you notice any compliance oversights, please send a patch via pull request. 32 | 33 | 34 | ## Feature Requests 35 | 36 | If you have a proposal or a feature request, you may create an issue with `[Proposal]` in the title. 37 | 38 | The proposal should also describe the new feature, as well as implementation ideas. The proposal will then be reviewed and either approved or denied. Once a proposal is approved, a pull request may be created implementing the new feature. 39 | 40 | 41 | ## Git Flow 42 | 43 | This project follows [Git-Flow](http://nvie.com/posts/a-successful-git-branching-model/), and as such has `master` (latest stable releases), `develop` (latest WIP development) and X.Y support branches (when there's multiple major versions). 44 | 45 | Accordingly all pull requests MUST be sent to the `develop` branch. 46 | 47 | > **Note:** Pull requests which do not follow these guidelines will be closed without any further notice. 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2021, Rinvex LLC, 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rinvex Testimonials 2 | 3 | ⚠️ This package is abandoned and no longer maintained. No replacement package was suggested. ⚠️ 4 | 5 | 👉 If you are interested to step on as the main maintainer of this package, please [reach out to me](https://twitter.com/omranic)! 6 | 7 | --- 8 | 9 | **Rinvex Testimonials** is a polymorphic Laravel package for managing testimonials. Customers can give you testimonials, and you can approve or disapprove each individually. Testimonials are good for showing the passion and love your service gets from customers, encouraging others to join the hype! 10 | 11 | [![Packagist](https://img.shields.io/packagist/v/rinvex/laravel-testimonials.svg?label=Packagist&style=flat-square)](https://packagist.org/packages/rinvex/laravel-testimonials) 12 | [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/rinvex/laravel-testimonials.svg?label=Scrutinizer&style=flat-square)](https://scrutinizer-ci.com/g/rinvex/laravel-testimonials/) 13 | [![Travis](https://img.shields.io/travis/rinvex/laravel-testimonials.svg?label=TravisCI&style=flat-square)](https://travis-ci.org/rinvex/laravel-testimonials) 14 | [![StyleCI](https://styleci.io/repos/114939264/shield)](https://styleci.io/repos/114939264) 15 | [![License](https://img.shields.io/packagist/l/rinvex/laravel-testimonials.svg?label=License&style=flat-square)](https://github.com/rinvex/laravel-testimonials/blob/develop/LICENSE) 16 | 17 | 18 | ## Installation 19 | 20 | 1. Install the package via composer: 21 | ```shell 22 | composer require rinvex/laravel-testimonials 23 | ``` 24 | 25 | 2. Publish resources (migrations and config files): 26 | ```shell 27 | php artisan rinvex:publish:testimonials 28 | ``` 29 | 30 | 3. Execute migrations via the following command: 31 | ```shell 32 | php artisan rinvex:migrate:testimonials 33 | ``` 34 | 35 | 4. Done! 36 | 37 | 38 | ## Usage 39 | 40 | Before going through the code samples, we need to clarify the concepts behind this package and how it works. **Rinvex Testimonials** assumes that every testimonial has two relationships, the is the entity giving the testimonial **(called attestant)**, and second is the enity receiving it **(called subject)**. These entities could be anything, each and every testimonial stores `type` and `id` (both form a polymorphic relationship) for **subject** and **attestant**. An entity can give testimonials, receive testimonials, or both. It's up to you to decide. 41 | 42 | ### Add giving testimonials functionality to your model 43 | 44 | To add support for a model to give testimonials simply use the `\Rinvex\Testimonials\Traits\GivesTestimonials` trait: 45 | 46 | ```php 47 | namespace App\Models; 48 | 49 | use Illuminate\Database\Eloquent\Model; 50 | use Rinvex\Testimonials\Traits\GivesTestimonials; 51 | 52 | class User extends Model 53 | { 54 | use GivesTestimonials; 55 | } 56 | ``` 57 | 58 | ### Add receiving testimonials functionality to your model 59 | 60 | To add support for a model to receive testimonials simply use the `\Rinvex\Testimonials\Traits\TakesTestimonials` trait: 61 | 62 | ```php 63 | namespace App\Models; 64 | 65 | use Illuminate\Database\Eloquent\Model; 66 | use Rinvex\Testimonials\Traits\TakesTestimonials; 67 | 68 | class Company extends Model 69 | { 70 | use TakesTestimonials; 71 | } 72 | ``` 73 | 74 | Both traits could be used together for the same model without any issues. 75 | 76 | ### Create a new testimonial 77 | 78 | Creating a new testimonial is straight forward, and could be done in many ways, use whatever suits your context. Let's see how could we do that: 79 | 80 | ```php 81 | $user = \App\Models\User::find(1); 82 | $company = \App\Models\Company::find(1); 83 | $testimonial = app('rinvex.testimonials.testimonial'); 84 | $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.'; 85 | 86 | // Create a new testimonial via subject model (attestant, body) 87 | $company->newTestimonial($user, $testimonialBody); 88 | 89 | // Create a new testimonial via attestant model (subject, body) 90 | $user->newTestimonial($company, $testimonialBody); 91 | 92 | // Create a new testimonial explicitly 93 | $testimonial->make(['body' => $testimonialBody]) 94 | ->subject()->associate($company) 95 | ->attestant()->associate($user) 96 | ->save(); 97 | ``` 98 | 99 | ### Query testimonial models 100 | 101 | You can get more details about a specific testimonial as follows: 102 | 103 | ```php 104 | $testimonial = app('rinvex.testimonials.testimonial')->find(1); 105 | 106 | $company = $testimonial->subject; // Get the owning company model 107 | $user = $testimonial->attestant; // Get the owning user model 108 | 109 | $testimonialsOfCompany = app('rinvex.testimonials.testimonial')->ofSubject($company)->get(); // Get testimonials of the given company 110 | $recommendationsOfUser = app('rinvex.testimonials.testimonial')->ofAttestant($user)->get(); // Get testimonials of the given user 111 | 112 | $company->testimonialsOf($user)->get(); // Get testimonials of the given user 113 | $user->recommendationsOf($company)->get(); // Get testimonials by the user for the given company 114 | 115 | $user->recommendations; // Get given testimonials collection 116 | $user->recommendations(); // Get given testimonials query builder 117 | 118 | $company->testimonials; // Get received testimonials collection 119 | $company->testimonials(); // Get received testimonials query builder 120 | ``` 121 | 122 | And not surprisingly, the `\Rinvex\Testimonials\Models\Testimonial` model itself extends [Eloquent](https://laravel.com/docs/master/eloquent) so you can manage it fluently as you normally do. 123 | 124 | 125 | ## Changelog 126 | 127 | Refer to the [Changelog](CHANGELOG.md) for a full history of the project. 128 | 129 | 130 | ## Support 131 | 132 | The following support channels are available at your fingertips: 133 | 134 | - [Chat on Slack](https://bit.ly/rinvex-slack) 135 | - [Help on Email](mailto:help@rinvex.com) 136 | - [Follow on Twitter](https://twitter.com/rinvex) 137 | 138 | 139 | ## Contributing & Protocols 140 | 141 | Thank you for considering contributing to this project! The contribution guide can be found in [CONTRIBUTING.md](CONTRIBUTING.md). 142 | 143 | Bug reports, feature requests, and pull requests are very welcome. 144 | 145 | - [Versioning](CONTRIBUTING.md#versioning) 146 | - [Pull Requests](CONTRIBUTING.md#pull-requests) 147 | - [Coding Standards](CONTRIBUTING.md#coding-standards) 148 | - [Feature Requests](CONTRIBUTING.md#feature-requests) 149 | - [Git Flow](CONTRIBUTING.md#git-flow) 150 | 151 | 152 | ## Security Vulnerabilities 153 | 154 | If you discover a security vulnerability within this project, please send an e-mail to [help@rinvex.com](help@rinvex.com). All security vulnerabilities will be promptly testimonialed. 155 | 156 | 157 | ## About Rinvex 158 | 159 | Rinvex is a software solutions startup, specialized in integrated enterprise solutions for SMEs established in Alexandria, Egypt since June 2016. We believe that our drive The Value, The Reach, and The Impact is what differentiates us and unleash the endless possibilities of our philosophy through the power of software. We like to call it Innovation At The Speed Of Life. That’s how we do our share of advancing humanity. 160 | 161 | 162 | ## License 163 | 164 | This software is released under [The MIT License (MIT)](LICENSE). 165 | 166 | (c) 2016-2021 Rinvex LLC, Some rights reserved. 167 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rinvex/laravel-testimonials", 3 | "description": "Rinvex Testimonials is a polymorphic Laravel package for managing testimonials. Customers can give you testimonials, and you can approve or disapprove each individually. Testimonials are good for showing the passion and love your service gets from customers, encouraging others to join the hype!", 4 | "type": "library", 5 | "keywords": [ 6 | "user", 7 | "model", 8 | "rinvex", 9 | "laravel", 10 | "eloquent", 11 | "attestant", 12 | "polymorphic", 13 | "testimonials", 14 | "recommendations" 15 | ], 16 | "license": "MIT", 17 | "homepage": "https://rinvex.com", 18 | "support": { 19 | "email": "help@rinvex.com", 20 | "issues": "https://github.com/rinvex/laravel-testimonials/issues", 21 | "source": "https://github.com/rinvex/laravel-testimonials", 22 | "docs": "https://github.com/rinvex/laravel-testimonials/blob/master/README.md" 23 | }, 24 | "authors": [ 25 | { 26 | "name": "Rinvex LLC", 27 | "homepage": "https://rinvex.com", 28 | "email": "help@rinvex.com" 29 | }, 30 | { 31 | "name": "Abdelrahman Omran", 32 | "homepage": "https://omranic.com", 33 | "email": "me@omranic.com", 34 | "role": "Project Lead" 35 | }, 36 | { 37 | "name": "The Generous Laravel Community", 38 | "homepage": "https://github.com/rinvex/laravel-testimonials/contributors" 39 | } 40 | ], 41 | "require": { 42 | "php": "^7.4.0 || ^8.0.0", 43 | "illuminate/console": "^8.0.0 || ^9.0.0", 44 | "illuminate/database": "^8.0.0 || ^9.0.0", 45 | "illuminate/support": "^8.0.0 || ^9.0.0", 46 | "rinvex/laravel-support": "^5.0.0" 47 | }, 48 | "require-dev": { 49 | "codedungeon/phpunit-result-printer": "^0.30.0", 50 | "illuminate/container": "^8.0.0 || ^9.0.0", 51 | "phpunit/phpunit": "^9.5.0" 52 | }, 53 | "autoload": { 54 | "psr-4": { 55 | "Rinvex\\Testimonials\\": "src/" 56 | } 57 | }, 58 | "autoload-dev": { 59 | "psr-4": { 60 | "Rinvex\\Testimonials\\Tests\\": "tests" 61 | } 62 | }, 63 | "scripts": { 64 | "test": "vendor/bin/phpunit" 65 | }, 66 | "config": { 67 | "sort-packages": true, 68 | "preferred-install": "dist", 69 | "optimize-autoloader": true 70 | }, 71 | "extra": { 72 | "laravel": { 73 | "providers": [ 74 | "Rinvex\\Testimonials\\Providers\\TestimonialsServiceProvider" 75 | ] 76 | } 77 | }, 78 | "minimum-stability": "dev", 79 | "prefer-stable": true 80 | } 81 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | true, 9 | 10 | // Testimonials Database Tables 11 | 'tables' => [ 12 | 'testimonials' => 'testimonials', 13 | ], 14 | 15 | // Testimonials Models 16 | 'models' => [ 17 | 'testimonial' => \Rinvex\Testimonials\Models\Testimonial::class, 18 | ], 19 | 20 | ]; 21 | -------------------------------------------------------------------------------- /database/migrations/2020_01_01_000001_create_testimonials_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 16 | $table->morphs('subject'); 17 | $table->morphs('attestant'); 18 | $table->boolean('is_approved')->default(false); 19 | $table->string('body')->nullable(); 20 | $table->timestamps(); 21 | $table->softDeletes(); 22 | }); 23 | } 24 | 25 | public function down() 26 | { 27 | Schema::dropIfExists(config('rinvex.testimonials.tables.testimonials')); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /phpstan.neon.dist: -------------------------------------------------------------------------------- 1 | includes: 2 | - ./vendor/nunomaduro/larastan/extension.neon 3 | parameters: 4 | level: 5 5 | paths: 6 | - src 7 | -------------------------------------------------------------------------------- /src/Console/Commands/MigrateCommand.php: -------------------------------------------------------------------------------- 1 | alert($this->description); 33 | 34 | $path = config('rinvex.testimonials.autoload_migrations') ? 35 | 'vendor/rinvex/laravel-testimonials/database/migrations' : 36 | 'database/migrations/rinvex/laravel-testimonials'; 37 | 38 | if (file_exists($path)) { 39 | $this->call('migrate', [ 40 | '--step' => true, 41 | '--path' => $path, 42 | '--force' => $this->option('force'), 43 | ]); 44 | } else { 45 | $this->warn('No migrations found! Consider publish them first: php artisan rinvex:publish:testimonials'); 46 | } 47 | 48 | $this->line(''); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Console/Commands/PublishCommand.php: -------------------------------------------------------------------------------- 1 | alert($this->description); 33 | 34 | collect($this->option('resource') ?: ['config', 'migrations'])->each(function ($resource) { 35 | $this->call('vendor:publish', ['--tag' => "rinvex/testimonials::{$resource}", '--force' => $this->option('force')]); 36 | }); 37 | 38 | $this->line(''); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Console/Commands/RollbackCommand.php: -------------------------------------------------------------------------------- 1 | alert($this->description); 33 | 34 | $path = config('rinvex.testimonials.autoload_migrations') ? 35 | 'vendor/rinvex/laravel-testimonials/database/migrations' : 36 | 'database/migrations/rinvex/laravel-testimonials'; 37 | 38 | if (file_exists($path)) { 39 | $this->call('migrate:reset', [ 40 | '--path' => $path, 41 | '--force' => $this->option('force'), 42 | ]); 43 | } else { 44 | $this->warn('No migrations found! Consider publish them first: php artisan rinvex:publish:testimonials'); 45 | } 46 | 47 | $this->line(''); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Models/Testimonial.php: -------------------------------------------------------------------------------- 1 | 'integer', 63 | 'subject_type' => 'string', 64 | 'attestant_id' => 'integer', 65 | 'attestant_type' => 'string', 66 | 'is_approved' => 'boolean', 67 | 'body' => 'string', 68 | 'deleted_at' => 'datetime', 69 | ]; 70 | 71 | /** 72 | * {@inheritdoc} 73 | */ 74 | protected $observables = [ 75 | 'validating', 76 | 'validated', 77 | ]; 78 | 79 | /** 80 | * The default rules that the model will validate against. 81 | * 82 | * @var array 83 | */ 84 | protected $rules = [ 85 | 'subject_id' => 'required|integer', 86 | 'subject_type' => 'required|string|strip_tags|max:150', 87 | 'attestant_id' => 'required|integer', 88 | 'attestant_type' => 'required|string|strip_tags|max:150', 89 | 'is_approved' => 'sometimes|boolean', 90 | 'body' => 'required|string|strip_tags|max:150', 91 | ]; 92 | 93 | /** 94 | * Whether the model should throw a 95 | * ValidationException if it fails validation. 96 | * 97 | * @var bool 98 | */ 99 | protected $throwValidationExceptions = true; 100 | 101 | /** 102 | * Create a new Eloquent model instance. 103 | * 104 | * @param array $attributes 105 | */ 106 | public function __construct(array $attributes = []) 107 | { 108 | parent::__construct($attributes); 109 | 110 | $this->setTable(config('rinvex.testimonials.tables.testimonials')); 111 | } 112 | 113 | /** 114 | * Get testimonials of the given subject. 115 | * 116 | * @param \Illuminate\Database\Eloquent\Builder $builder 117 | * @param \Illuminate\Database\Eloquent\Model $subject 118 | * 119 | * @return \Illuminate\Database\Eloquent\Builder 120 | */ 121 | public function scopeOfSubject(Builder $builder, Model $subject): Builder 122 | { 123 | return $builder->where('subject_type', $subject->getMorphClass())->where('subject_id', $subject->getKey()); 124 | } 125 | 126 | /** 127 | * Get testimonials of the given attestant. 128 | * 129 | * @param \Illuminate\Database\Eloquent\Builder $builder 130 | * @param \Illuminate\Database\Eloquent\Model $attestant 131 | * 132 | * @return \Illuminate\Database\Eloquent\Builder 133 | */ 134 | public function scopeOfAttestant(Builder $builder, Model $attestant): Builder 135 | { 136 | return $builder->where('attestant_type', $attestant->getMorphClass())->where('attestant_id', $attestant->getKey()); 137 | } 138 | 139 | /** 140 | * Get the approved testimonials. 141 | * 142 | * @param \Illuminate\Database\Eloquent\Builder $builder 143 | * 144 | * @return \Illuminate\Database\Eloquent\Builder 145 | */ 146 | public function scopeApproved(Builder $builder): Builder 147 | { 148 | return $builder->where('is_approved', true); 149 | } 150 | 151 | /** 152 | * Get the disapproved testimonials. 153 | * 154 | * @param \Illuminate\Database\Eloquent\Builder $builder 155 | * 156 | * @return \Illuminate\Database\Eloquent\Builder 157 | */ 158 | public function scopeDisapproved(Builder $builder): Builder 159 | { 160 | return $builder->where('is_approved', false); 161 | } 162 | 163 | /** 164 | * Get the subject model of the testimonial. 165 | * 166 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 167 | */ 168 | public function subject(): MorphTo 169 | { 170 | return $this->morphTo('subject', 'subject_type', 'subject_id', 'id'); 171 | } 172 | 173 | /** 174 | * Get the attestant model of the testimonial. 175 | * 176 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo 177 | */ 178 | public function attestant(): MorphTo 179 | { 180 | return $this->morphTo('attestant', 'attestant_type', 'attestant_id', 'id'); 181 | } 182 | 183 | /** 184 | * Approve the testimonial. 185 | * 186 | * @return $this 187 | */ 188 | public function approve() 189 | { 190 | $this->update(['is_approved' => true]); 191 | 192 | return $this; 193 | } 194 | 195 | /** 196 | * Disapprove the testimonial. 197 | * 198 | * @return $this 199 | */ 200 | public function disapprove() 201 | { 202 | $this->update(['is_approved' => false]); 203 | 204 | return $this; 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /src/Providers/TestimonialsServiceProvider.php: -------------------------------------------------------------------------------- 1 | 'command.rinvex.testimonials.migrate', 25 | PublishCommand::class => 'command.rinvex.testimonials.publish', 26 | RollbackCommand::class => 'command.rinvex.testimonials.rollback', 27 | ]; 28 | 29 | /** 30 | * {@inheritdoc} 31 | */ 32 | public function register() 33 | { 34 | // Merge config 35 | $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.testimonials'); 36 | 37 | // Bind eloquent models to IoC container 38 | $this->app->singleton('rinvex.testimonials.testimonial', $testimonialModel = $this->app['config']['rinvex.testimonials.models.testimonial']); 39 | $testimonialModel === Testimonial::class || $this->app->alias('rinvex.testimonials.testimonial', Testimonial::class); 40 | 41 | // Register console commands 42 | $this->registerCommands($this->commands); 43 | } 44 | 45 | /** 46 | * {@inheritdoc} 47 | */ 48 | public function boot() 49 | { 50 | // Publish Resources 51 | $this->publishesConfig('rinvex/laravel-testimonials'); 52 | $this->publishesMigrations('rinvex/laravel-testimonials'); 53 | ! $this->autoloadMigrations('rinvex/laravel-testimonials') || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Traits/GivesTestimonials.php: -------------------------------------------------------------------------------- 1 | recommendations()->delete(); 44 | }); 45 | } 46 | 47 | /** 48 | * Get all attached testimonials to the model. 49 | * 50 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 51 | */ 52 | public function recommendations(): MorphMany 53 | { 54 | return $this->morphMany(config('rinvex.testimonials.models.testimonial'), 'attestant'); 55 | } 56 | 57 | /** 58 | * Get recommendations for the given subject. 59 | * 60 | * @param \Illuminate\Database\Eloquent\Model $subject 61 | * 62 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 63 | */ 64 | public function recommendationsOf(Model $subject): MorphMany 65 | { 66 | return $this->recommendations()->where('subject_type', $subject->getMorphClass())->where('subject_id', $subject->getKey()); 67 | } 68 | 69 | /** 70 | * Add new testimonial for the given subject. 71 | * 72 | * @param \Illuminate\Database\Eloquent\Model $subject 73 | * @param string $body 74 | * 75 | * @return \Rinvex\Testimonials\Models\Testimonial 76 | */ 77 | public function newTestimonial(Model $subject, string $body): Testimonial 78 | { 79 | return $this->recommendations()->create([ 80 | 'body' => $body, 81 | 'subject_id' => $subject->getKey(), 82 | 'subject_type' => $subject->getMorphClass(), 83 | 'attestant_id' => static::getKey(), 84 | 'attestant_type' => static::getMorphClass(), 85 | ]); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/Traits/TakesTestimonials.php: -------------------------------------------------------------------------------- 1 | testimonials()->delete(); 44 | }); 45 | } 46 | 47 | /** 48 | * Get all attached testimonials to the model. 49 | * 50 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 51 | */ 52 | public function testimonials(): MorphMany 53 | { 54 | return $this->morphMany(config('rinvex.testimonials.models.testimonial'), 'attestant'); 55 | } 56 | 57 | /** 58 | * Get testimonials for the given attestant. 59 | * 60 | * @param \Illuminate\Database\Eloquent\Model $attestant 61 | * 62 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany 63 | */ 64 | public function testimonialsOf(Model $attestant): MorphMany 65 | { 66 | return $this->testimonials()->where('attestant_type', $attestant->getMorphClass())->where('attestant_id', $attestant->getKey()); 67 | } 68 | 69 | /** 70 | * Add new testimonial for the given attestant. 71 | * 72 | * @param \Illuminate\Database\Eloquent\Model $attestant 73 | * @param string $body 74 | * 75 | * @return \Rinvex\Testimonials\Models\Testimonial 76 | */ 77 | public function newTestimonial(Model $attestant, string $body): Testimonial 78 | { 79 | return $this->testimonials()->create([ 80 | 'body' => $body, 81 | 'subject_id' => static::getKey(), 82 | 'subject_type' => static::getMorphClass(), 83 | 'attestant_id' => $attestant->getKey(), 84 | 'attestant_type' => $attestant->getMorphClass(), 85 | ]); 86 | } 87 | } 88 | --------------------------------------------------------------------------------