akhaled/livewire-account-preferences

Edit account model using livewire

v0.0.7 2021-10-16 15:18 UTC

This package is auto-updated.

Last update: 2024-04-16 21:01:02 UTC


README

Display and update user preferences with livewire

The packages uses bootstrap 4 by default. In next release I will enable publishing views to your project directory so you can update them.

Installation

composer require akhaled/livewire-account-preferences

How to use

Very simple!

1. Add ServiceProvider in config/app.php

    ...
    Akhaled\LivewireAccountPreferences\ServiceProvider::class
    ...

2. Add livewire component markup in your code

edit.blade.php

...
@livewire('account-preferences-edit', [
    'account' => auth()->user()
    'view' => 'account.edit' // optional, overrides global config property
])
...

show.blade.php

...
@livewire('account-preferences-show', [
    'account' => auth()->user()
    'view' => 'account.show' // optional, overrides global config property
])
...

3. Include livewire-sweetalert scripts along with @livewireScripts

If you want to enable sweetalert2 toast.

...
    @livewireScripts
    @livewireSweetalertScripts
...

4. Extra config file

Publish the configs: php artisan vendor:publish --tag=livewire-account-preferences.

See available configuration

Define model fields

By default, package assume model has name, email and password fields. If Model class has defined $rules property it overrides default. Please don't make the password column required as changing password is done in separate stage. Also, you need to define another property to tell component about filed usage.

Example :

class User
{
    ...
    public $rules = [
        'first_name' => 'required|string|min:6',
        'last_name' => 'required|string|min:6',
        'email_address' => 'required|email|max:500',
        ...
    ];

    public $lwap = [
        'first_name' => 'name',
        'last_name' => 'name',
        'email_address' => 'email'
    ]
    ...
}

Available configuration

  • views:
    • edit: Global edit view resource location. If you submit a view with component it overrides the global config.
    • show: Global show view resource location. If you submit a view with component it overrides the global config.
  • routes:
    • edit: Edit route name. Default is /account
    • show: Show route name. Default is /account/edit

Todo

  • Publish blade views
  • Tailwind views