Giter VIP home page Giter VIP logo

laraconfig's Introduction

  • ๐Ÿ‘‹ Hi, Iโ€™m @DarkGhostHunter
  • ๐Ÿ‘€ Iโ€™m interested in great apps
  • ๐ŸŒฑ Iโ€™m currently surviving inflation
  • ๐Ÿ’ž๏ธ Iโ€™m looking to collaborate on my packages.
  • ๐Ÿ“ซ Reach me by email or in Mastodon.

laraconfig's People

Contributors

darkghosthunter avatar eafarooqi avatar greenspace10 avatar ricventu avatar szepeviktor avatar vanbosse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

laraconfig's Issues

Incorrect settable_type value upon migration

Hi,

I am facing issue that when I run the php artisan settings:migrate command my database gets nicely seeded how ever the models do not include backslashes there for $user->settings does not work.

However I found out that if I run $user->settings()->initialize() it will recreate all of the settings with proper settable_type including backslashes. Here is a screenshot:

image

I am able to solve this issue by editing the fillSettings method in Pipes\CreateNewMetadata.php file like this:
image
However I am not sure if it is the proper approach.

Can someone please help me why is this behavior here?

new tag?

Time for a new tag? Some bugs are missing in 1.3.5 :)

Migration of setting does not work

The migration of settings does not work

I have issued the

php artisan settings:publish

then

Setting::name('UserType')->integer();

and then

php artisan settings:migrate

which fails

S:\Composer\Laravel\Laraset\vendor\orchestra\testbench-core\laravel\settings/users.phpNo metadata exists in the database, and no declaration exists.

php artisan settings:migrate command not working

php artisan settings:migrate command not working

Cannot declare class App\Models\AnyModel, because the name is already in use

I tried remove this model, and this issue occurs again on next model in alphabetical order
looks like it swears at any model

Unable to locate publishable resources.

Hi,

when I run command - php artisan vendor:publish --provider="DarkGhostHunter\Laraconfig\LaraconfigServiceProvider" --tag="migrations"

I get the error:
Unable to locate publishable resources.
Publishing complete.

Before the command above i have entered: composer require darkghosthunter/laraconfig

Am i doing something wrong?

Laravel 9 unsupported

darkghosthunter/laraconfig dev-master requires illuminate/support ^8.43 -> satisfiable by illuminate/support[v8.43.0, ..., 8.x-dev].

Php artisan settings:publish fails with error

Hi,

it's me again. Sorry to bother you but when I run a command: php artisan settings:publish it fails with an error.

Error: ** copy(Laravel\settings/users.php): Failed to open stream: No such file or directory
**

I created the directory and file myself so when I run command again it created a symbolic link in laraconfig/stubs/users.php.

Thanks for everything this library looks awesome!

JsonException Syntax error when default value is null

when we create the settings as follows:

Setting::name('color')
    ->array()
    ->group('theme');

in this case default value for this setting should be null but in the table user_settings the default value is empty string, which creates as error when try to get the setting

i have to create the new items like below, otherwise we have error

Setting::name('color')->array()->default([])->group('theme');

Existing users are not initialized on migration

I have an existing codebase with many users already in the database. When I retrieve one of these existing users, their settings are not initialised. This results in the following error when I attempt to set the value of a setting on one of these users:

use App\Models\User;
$user = User::find(1);
$user->settings->set('dark_mode', true);

// RuntimeException with message 'The setting [dark_mode] doesn't exist.'

I have created a PR which resolves this by hooking into the retrieved Eloquent event within the HasConfig trait.

PR: Initialise when loading historic user records

The setting [color] doesn't exist.

hi,

no matter what setting i create, i get the error setting doesn't exist.
Laravel Version: 8.61.0
PHP 8

I can see the settings in table, they are enabled. Everything looks ok. Cache is disabled.

this is my user model

...
use DarkGhostHunter\Laraconfig\HasConfig;

class User extends Authenticatable implements LdapAuthenticatable
{
    use AuthenticatesWithLdap;
    use HasFactory, Notifiable;
    use HasLdapUser;
    use HasRoles;
    use HasConfig;
...

this is the settings/users.php file

<?php

use DarkGhostHunter\Laraconfig\Facades\Setting;

Setting::name('color')->string()->default('black');

This is how i am trying to get it. it always comes blank, even the value exists in database.

$user = User::find(1);
echo "Your color is: {$user->settings->get('color')}.";

if i try to set it i get setting doesn't exists, no matter how i try to set it.

$user = User::find(1);
$setting = $user->settings->get('color');

$setting->value = 'red';
$setting->save();

or

$user->settings->set([
    'color' => 'red'
]);

Column not found: 1054 Unknown column 'theme' in 'field list'

When initialising the settings I get this error:

Column not found: 1054 Unknown column 'theme' in 'field list' (SQL: insert into user_settings (settable_id, settable_type, metadata_id, theme, updated_at, created_at) values (1, App\Models\Company, 1, dark, 2022-02-15 10:01:07, 2022-02-15 10:01:07))

users.php:

Setting::name('display_name')->boolean()->default(false);

Setting::name('theme')->array()->default(['theme' => 'dark'])->group('companies')->bag('companies');

Initialization:

$user = User::first();
    
$user->company->settings()->initialize();

$user->settings()->initialize();

I'm initialising because I use a seeder to create the models.

I have migrated the settings and company is another model connected to user model by foreign ID.

User model:

namespace App\Models;

use Laravel\Sanctum\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use DarkGhostHunter\Laraconfig\HasConfig;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable, HasConfig;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'password',
        'company_id'
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    public function company()
    {
        return $this->belongsTo(Company::class);
    }
}

Company model:

namespace App\Models;

use DarkGhostHunter\Laraconfig\HasConfig;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Company extends Model
{
    use HasFactory, HasConfig;

    protected $fillable = [
        'name',
    ];
}

Am I missing something?

Note: I was able to create user settings but when I added company that's when the error started.

Versions:

  • "laravel/framework": "^8.75",
  • "darkghosthunter/laraconfig": "^1.3.5",

Test failed, Property does not exist on this collection instance

The functionality works perfectly on browser. But it keeps failing on feature test.

Here is my controller snippet.

public function update(Request $request)
{
    $settings = [ 
        'DARK_MODE',
        'SEND_NOTIFICATION_ON_NEW_PROJECT_REQUEST',
        'SEND_NOTIFICATION_ON_NEW_JOB_REQUEST'
    ];
    $user = auth()->user();
    $updatedReq = $request->only($settings);

    foreach ($updatedReq as $key => $value) {
        $user->settings->set($key, $value);
    }

    return Redirect::back();
}

Test Snippet

$response = $this->actingAs($this->creator)
            ->from('/settings')
            ->put('/settings', [
                'DARK_MODE' => 'LIGHT',
                'SEND_NOTIFICATION_ON_NEW_PROJECT_REQUEST' => false,
                'SEND_NOTIFICATION_ON_NEW_JOB_REQUEST' => true,
            ]);

Test Setup

public function setUp(): void
{
       parent::setUp();

       Metadata::forceCreate([
           'name'    => 'DARK_MODE',
           'type'    => 'string',
           'default' => 'AUTO',
       ]);
       Metadata::forceCreate([
           'name'    => 'SEND_NOTIFICATION_ON_NEW_PROJECT_REQUEST',
           'type'    => 'boolean',
           'default' => true,
       ]);
       Metadata::forceCreate([
           'name'    => 'SEND_NOTIFICATION_ON_NEW_JOB_REQUEST',
           'type'    => 'boolean',
           'default' => true,
       ]);
       $this->creator = User::factory()->create();
       $this->user = User::factory()->create();

       $this->creator->assignRole('CREATOR');
}

I can assure you, all the database seeded and migrated properly. I can do dd($user->settings) and it shows me all 3 items. But when I tried to update it using $user->settings->set($key, $value) on for each, it fails with the error

 Property [DARK_MODE] does not exist on this collection instance.

  at D:\Project\_kevinyobeth\SynchV2\vendor\laravel\framework\src\Illuminate\Collections\Traits\EnumeratesValues.php:912
    908โ–•      */
    909โ–•     public function __get($key)
    910โ–•     {
    911โ–•         if (! in_array($key, static::$proxies)) {
  โžœ 912โ–•             throw new Exception("Property [{$key}] does not exist on this collection instance.");
    913โ–•         }
    914โ–•
    915โ–•         return new HigherOrderCollectionProxy($this, $key);
    916โ–•     }

  1   D:\Project\_kevinyobeth\SynchV2\vendor\darkghosthunter\laraconfig\src\SettingsCollection.php:326
      DarkGhostHunter\Laraconfig\SettingsCollection::__dynamicGet("DARK_MODE")

  2   D:\Project\_kevinyobeth\SynchV2\tests\Feature\SettingsTest.php:68
      DarkGhostHunter\Laraconfig\SettingsCollection::__get("DARK_MODE")

Update 1

I tried getting the keys from the test, and real browser test, it returns different keys.
When I ran this
$user->settings->keys()
Result
["DARK_MODE","SEND_NOTIFICATION_ON_NEW_PROJECT_REQUEST","SEND_NOTIFICATION_ON_NEW_JOB_REQUEST"]

While on the test when I ran it, it returns
Result
[0,1,2]

My Workaround

To overcome this problem, I came up with this solution. I search the user setting manually in the controller and it works!

foreach ($updatedReq as $key => $value) {
    $setting = $user->settings->where('name', $key)->first();     
    $setting->value = $value;
    $setting->save();
}

Still getting the error

When I run php artisan settings:migrate I still get the following error:

Illuminate\Contracts\Container\BindingResolutionException

Target [Symfony\Component\Console\Output\OutputInterface] is not instantiable while building [DarkGhostHunter\Laraconfig\Migrator\Pipes\FlushCache, Illum
inate\Console\OutputStyle].

I also tried to reinstall the package.

I get the same error like before when I try to publish the package with the command php artisan vendor:publish --provider="DarkGhostHunter\Laraconfig\LaraconfigServiceProvider" --tag="migrations"

ERROR:
Unable to locate publishable resources.
Publishing complete.

Also when I run a command php artisan settings:publish

I get the error:

There are no commands defined in the "settings" namespace.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.