Skip to content

Commit

Permalink
Merge pull request #1 from starfolksoftware/feat/v1.x
Browse files Browse the repository at this point in the history
Feat/v1.x
  • Loading branch information
frknasir committed Oct 9, 2022
2 parents a3ff2c1 + 957e6dc commit 5f29067
Show file tree
Hide file tree
Showing 25 changed files with 927 additions and 74 deletions.
106 changes: 84 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
# Gauge is a simple Laravel package that makes your models reviewable
# Laravel Gauge

[![Latest Version on Packagist](https://img.shields.io/packagist/v/starfolksoftware/gauge.svg?style=flat-square)](https://packagist.org/packages/starfolksoftware/gauge)
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/starfolksoftware/gauge/run-tests?label=tests)](https://github.com/starfolksoftware/gauge/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/starfolksoftware/gauge/Fix%20PHP%20code%20style%20issues?label=code%20style)](https://github.com/starfolksoftware/gauge/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/starfolksoftware/gauge.svg?style=flat-square)](https://packagist.org/packages/starfolksoftware/gauge)

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

## Support us

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/gauge.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/gauge)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
Add reviews and ratings capabilities to your Laravel applications.

## Installation

Expand All @@ -23,34 +15,104 @@ You can install the package via composer:
composer require starfolksoftware/gauge
```

You can publish and run the migrations with:
To install the package, run the following command:

```bash
php artisan vendor:publish --tag="gauge-migrations"
php artisan migrate
php artisan gauge:install
```

You can publish the config file with:
## Configurations

```bash
php artisan vendor:publish --tag="gauge-config"
To disable migrations, add the following in the service provider:

```php
Gauge::ignoreMigrations();
```

This is the contents of the published config file:
To use a different `Review` model:

```php
return [
];
Gauge::useReviewModel('App\\Models\\CoolReviewModel');
```

Optionally, you can publish the views using
To specify the user model to be used with Gauge:

```bash
php artisan vendor:publish --tag="gauge-views"
```php
Gauge::useUserModel('App\\Models\\UserTestModel');
```

To specify the reviews table name,

```php
Gauge::useReviewsTableName('reviews_table');
```

To turn on support for soft deletiong,

```php
Gauge::supportsSoftDeletes();
```

To turn on support or single reviews, that is, each user can only review a model at most once:

```php
Gauge::supportsSingleReviews();
```

To turn on support for teams

```php
Gauge::supportsTeams();
```

## Usage

To make a model reviewable, add the `Reviewable` trait as in the following:

```php
use StarfolkSoftware\Gauge\Reviewable;

class Item extends Model
{
// ...
use Reviewable;
// ...
}
```

To create a review on a reviewable model,

```php
$branch->review($user, $rating, $comment)
```

To setup the team support, add the `TeamHasReviews` trait to the team model,

```php
use StarfolkSoftware\Gauge\TeamHasReviews;

class Team extends Model
{
use TeamHasReviews;

protected $table = 'teams';
}
```

To create a review for a team,

```php
$team->reviews()->save([
//...
]);
```

To fetch reviews of a team,

```php
$team->reviews
```

```php
$gauge = new StarfolkSoftware\Gauge();
echo $gauge->echoPhrase('Hello, StarfolkSoftware!');
Expand Down
19 changes: 0 additions & 19 deletions database/factories/ModelFactory.php

This file was deleted.

13 changes: 11 additions & 2 deletions database/migrations/create_gauge_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use StarfolkSoftware\Gauge\Gauge;

return new class extends Migration
{
public function up()
{
Schema::create('gauge_table', function (Blueprint $table) {
Schema::create(Gauge::$reviewsTableName, function (Blueprint $table) {
$table->id();

// add fields
$table->unsignedBigInteger('team_id')->nullable();
$table->unsignedBigInteger('user_id')->nullable();
$table->morphs('reviewable');
$table->integer('rating');
$table->text('comment')->nullable();

$table->timestamps();

if (config('gauge.soft_deletion')) {
$table->softDeletes();
}
});
}
};
19 changes: 0 additions & 19 deletions src/Commands/GaugeCommand.php

This file was deleted.

59 changes: 59 additions & 0 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace StarfolkSoftware\Gauge\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Str;

class InstallCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
public $signature = 'gauge:install';

public $description = 'Install the Gauge package and resources';

public function handle(): int
{
// Publish...
$this->callSilent('vendor:publish', ['--tag' => 'gauge-config', '--force' => true]);
$this->callSilent('vendor:publish', ['--tag' => 'gauge-migrations', '--force' => true]);

// Models...
copy(__DIR__.'/../../stubs/app/Models/Review.php', app_path('Models/Review.php'));

// Factories
copy(__DIR__.'/../../stubs/database/factories/ReviewFactory.php', app_path('../database/factories/ReviewFactory.php'));

// Policies...
copy(__DIR__.'/../../stubs/app/Policies/ReviewPolicy.php', app_path('Policies/ReviewPolicy.php'));

// Service Providers...
copy(__DIR__.'/../../stubs/app/Providers/GaugeServiceProvider.php', app_path('Providers/GaugeServiceProvider.php'));

$this->installServiceProviderAfter('RouteServiceProvider', 'GaugeServiceProvider');

return self::SUCCESS;
}

/**
* Install the service provider in the application configuration file.
*
* @param string $after
* @param string $name
* @return void
*/
protected function installServiceProviderAfter($after, $name)
{
if (! Str::contains($appConfig = file_get_contents(config_path('app.php')), 'App\\Providers\\'.$name.'::class')) {
file_put_contents(config_path('app.php'), str_replace(
'App\\Providers\\'.$after.'::class,',
'App\\Providers\\'.$after.'::class,'.PHP_EOL.' App\\Providers\\'.$name.'::class,',
$appConfig
));
}
}
}
Loading

0 comments on commit 5f29067

Please sign in to comment.