Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop #3

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions Configs/uuider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

'models' => [

'client' => \App\Containers\Vendor\Uuider\Models\Client::class,
'client' => \App\Containers\Larabeans\Uuider\Models\Client::class,

'personal_access_client' => \App\Containers\Vendor\Uuider\Models\PersonalAccessClient::class,
'personal_access_client' => \App\Containers\Larabeans\Uuider\Models\PersonalAccessClient::class,
],

// Containers to skip primary key type conversion from auto-increment to uuid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public function up()
});

Schema::table('oauth_personal_access_clients', function (Blueprint $table) {
$table->uuid('id')->primary()->first();
$table->uuid('client_id')->change();
});
$table->uuid('id')->primary()->first();
$table->uuid('client_id')->change();
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UpdateShipJobTablesPrimaryKeyTypeToUuid extends Migration
*/
public function up()
{
if(Config::get('queue.default') == 'database'){
if (Config::get('queue.default') == 'database') {

// First drop `id` column, so they can be re-added with new type.
Schema::table('jobs', function (Blueprint $table) {
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Larabeans

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 3 additions & 3 deletions Models/Client.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
namespace App\Containers\Vendor\Uuider\Models;

namespace App\Containers\Larabeans\Uuider\Models;

use Laravel\Passport\Client as OAuthClient;
use App\Containers\Vendor\Beaner\Traits\HasUuid;
use App\Containers\Larabeans\Uuider\Traits\HasUuid;

class Client extends OAuthClient
{
use HasUuid;

}
6 changes: 3 additions & 3 deletions Models/PersonalAccessClient.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
namespace App\Containers\Vendor\Uuider\Models;

namespace App\Containers\Larabeans\Uuider\Models;

use Laravel\Passport\PersonalAccessClient as OAuthPersonalAccessClient;
use App\Containers\Vendor\Beaner\Traits\HasUuid;
use App\Containers\Larabeans\Uuider\Traits\HasUuid;

class PersonalAccessClient extends OAuthPersonalAccessClient
{
use HasUuid;

}
14 changes: 7 additions & 7 deletions Providers/MainServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?php

namespace App\Containers\Vendor\Uuider\Providers;
namespace App\Containers\Larabeans\Uuider\Providers;

use App\Ship\Parents\Providers\MainProvider;
use App\Ship\Parents\Providers\MainServiceProvider as ParentMainServiceProvider;
use Laravel\Passport\Passport;

class MainServiceProvider extends MainProvider
class MainServiceProvider extends ParentMainServiceProvider
{
public function boot(): void
{
// To use customize passport models to replace primary key type from auto-increment to uuid.
Passport::useClientModel(config('uuider.models.client',\App\Containers\Vendor\Uuider\Models\Client::class));
Passport::usePersonalAccessClientModel(config('uuider.models.personal_access_client',\App\Containers\Vendor\Uuider\Models\PersonalAccessClient::class));
Passport::useClientModel(config('uuider.models.client', \App\Containers\Larabeans\Uuider\Models\Client::class));
Passport::usePersonalAccessClientModel(config('uuider.models.personal_access_client', \App\Containers\Larabeans\Uuider\Models\PersonalAccessClient::class));
}

public function register(): void
{
// Over-write permission configuration on run time to
// update role and permissions models
config(['permission.models.permission' => config('beaner.models.permission', \App\Containers\Vendor\Beaner\Models\Permission::class)]);
config(['permission.models.role' => config('beaner.models.role', \App\Containers\Vendor\Beaner\Models\Role::class)]);
config(['permission.models.permission' => config('core.models.permission', \App\Containers\Larabeans\Core\Models\Permission::class)]);
config(['permission.models.role' => config('core.models.role', \App\Containers\Larabeans\Core\Models\Role::class)]);
}

}
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
>[Larabeans](README.md) > Uuider
> [Larabeans](README.md) > Uuider

---

Expand All @@ -18,29 +18,36 @@
---

## Migrations

Contains new migrations to update core tables primary key type to uuid, which is incremental by default.

---

## Models

Adds new models.

- Client
- PersonalAccessClient

- User, Role and Permission models are used that are provided in core (beaner container). If you want to use your own models, write your own model and use HasUuid trait in your custom models. Or just extend existing models and add your custom functionality in those models. You also have to update core (beaner) config file models values to make this work for your custom models
- User, Role and Permission models are used that are provided in core container. If you want to use your own
models, write your own model and use HasUuid trait in your custom models. Or just extend existing models and add your
custom functionality in those models. You also have to update core config file models values to make this
work for your custom models

---

## Environment File
- Update env file user namespace as USER_NAMESPACE=App\Containers\Vendor\Beaner\Models\

OR
- Update env file user namespace as USER_NAMESPACE=App\Containers\Larabeans\Core\Models\

OR

Create you own user model and use trait from core (beaner) container as
Create you own user model and use trait from core container as

```phpt
use HasUuid;
```

---
>[Larabeans](README.md) > Uuider [⬆](#uuider)
> [Larabeans](README.md) > Uuider [⬆](#uuider)
39 changes: 39 additions & 0 deletions Traits/HasUuid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Containers\Larabeans\Uuider\Traits;

use Facades\Str;

/**
* Class HasUuid.
*
* @author Syed Ali Kazmi <[email protected]>
*/
trait HasUuid
{
/**
* Boot function from laravel.
*/
protected static function bootHasUuid()
{
if (config('uuider.installed', false)) {
static::creating(function ($model) {
if (!$model->getIncrementing()) {
$model->keyType = 'string';
$model->incrementing = false;
$model->{$model->getKeyName()} = $model->{$model->getKeyName()} ?: (string)Str::orderedUuid();
}
});
}
}

public function getIncrementing()
{
return !config('uuider.installed', false);
}

public function getKeyType()
{
return config('uuider.installed', false) ? 'string' : 'integer';
}
}
6 changes: 4 additions & 2 deletions WARNING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
THIS CONTAINER CAN ONLY BE USED WITH FRESH PROJECTS. DON'T USE WITH EXISTING PROJECTS OTHERWISE YOU CAN LOOSE YOUR DATA.

This container can only be installed at start of your project.
This container can only be installed at start of your project.

If you already started project with primary key type as auto increment (which is default) don't install this container. As this modifies database table columns typs by dropping existing primary column and adding new ones, which may result in loose of existing data.
If you already started project with primary key type as auto increment (which is default) don't install this container.
As this modifies database table columns typs by dropping existing primary column and adding new ones, which may result
in loose of existing data.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "larabeans/uuider",
"description": "Apiato container to replace primary key type from auto-increment to uuid.",
"type": "apiato-container",
"type": "larabeans-container",
"homepage": "https://larabeans.com/",
"version": "0.1.0",
"support": {
Expand Down Expand Up @@ -29,6 +29,7 @@
"extra": {
"apiato": {
"container": {
"section": "Larabeans",
"name": "Uuider"
}
}
Expand Down