-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Visanduma/file-uploading
File uploading basic workaround
- Loading branch information
Showing
12 changed files
with
342 additions
and
25,651 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,255 @@ | ||
## 🚧 UNDER DEELOPMENT 🚧 ## | ||
<!-- <p align="center"> | ||
### Nova Settings | ||
<img src="https://github.com/Visanduma/nova-settings/blob/file-uploading/cover.png?raw=true" /> | ||
Complete Settings management package for Laravel Nova ™ dashboard using **Native fields** | ||
</p> --> | ||
|
||
### Install | ||
|
||
composer command | ||
# ⚙ Nova Settings | ||
|
||
### Configuration | ||
Settings management UI for Laravel Nova™ dashboard using **Native fields** | ||
|
||
migration | ||
config file | ||
trait | ||
|
||
### Create your first setting page | ||
![screenshot1](./sc1.png) | ||
|
||
fields | ||
validation | ||
<br> | ||
|
||
### Supported fields | ||
### 💠 Install | ||
|
||
### Registering settings | ||
```bash | ||
composer require visanduma/nova-settings | ||
``` | ||
<br> | ||
|
||
automatic | ||
manual | ||
### 💠 Configuration | ||
|
||
### Panels | ||
Publish config & migrations | ||
|
||
### Customizing section | ||
``` | ||
php artisan vendor:publish --tag=nova-settings | ||
``` | ||
|
||
icon | ||
label | ||
uriKey | ||
Run migration | ||
|
||
### User settings vs Global settings | ||
``` | ||
php artisan migrate | ||
``` | ||
|
||
### Retrieving the settings | ||
Update config file (optional) | ||
|
||
user | ||
global | ||
```php | ||
|
||
### Transforming inputs | ||
<?php | ||
|
||
### Hooks | ||
return [ | ||
/* default path for load settings class */ | ||
'settings_path' => app_path('Nova/Settings'), | ||
]; | ||
|
||
``` | ||
|
||
Use trait in Model. generally in `User.php` | ||
|
||
```php | ||
use Visanduma\NovaSettings\HasNovaSettings; | ||
|
||
class User extends Authenticatable | ||
{ | ||
use HasNovaSettings; | ||
|
||
} | ||
|
||
``` | ||
<br> | ||
|
||
### 💠 Create your first setting class | ||
|
||
You can use `nova-settings:create` command to build a fresh settings class | ||
|
||
``` | ||
php artisan nova-settings:create Contact | ||
``` | ||
|
||
Adding fields is the same as in Nova Resource | ||
|
||
```php | ||
class Contact extends NovaSettingsMum | ||
|
||
{ | ||
|
||
public $icon = 'phone'; | ||
|
||
|
||
public function fields() | ||
|
||
{ | ||
|
||
return [ | ||
|
||
Text::make('Name')->rules('required'), | ||
|
||
Text::make('Address')->rules('required'), | ||
|
||
Text::make('City')->rules('required'), | ||
|
||
Select::make('Province')->options([ | ||
'NC' => 'North Central', | ||
'N' => 'Northern', | ||
]), | ||
|
||
Country::make('Country')->rules('required'), | ||
|
||
Panel::make('Home', [ | ||
|
||
Text::make('Contact name'), | ||
|
||
Text::make('Phone'), | ||
|
||
])->help('Update you home contacts'), | ||
|
||
]; | ||
|
||
} | ||
} | ||
|
||
``` | ||
<br> | ||
|
||
### 💠 Registering settings | ||
|
||
All settings class in the default path are automatically registered. If you are going to use a different path, please configure it in `nova-settings.php` | ||
|
||
If you want to register settings class manually, use `NovaSettings::register` method in the service provider | ||
|
||
```php | ||
namespace App\Nova\Settings; | ||
|
||
public function boot() | ||
|
||
{ | ||
NovaSettings::register([ | ||
Contact::class, | ||
]); | ||
} | ||
``` | ||
<br> | ||
|
||
### 💠 Customizing the settings class | ||
|
||
You can customize settings class as per your needs | ||
|
||
Customizing settings menu icon. you can use any [Heroicons](https://v1.heroicons.com/) | ||
|
||
```php | ||
public $icon = 'bell'; | ||
``` | ||
|
||
Customizing section label | ||
|
||
```php | ||
public function label():string | ||
|
||
{ | ||
|
||
return 'User contacts'; | ||
|
||
} | ||
``` | ||
|
||
Customizing uriKey. `uriKey` is used when saving/retrieving the settings | ||
|
||
```php | ||
public function uriKey(): string | ||
|
||
{ | ||
return 'user-contacts'; | ||
} | ||
``` | ||
<br> | ||
|
||
### 💠 User settings vs Global settings | ||
|
||
There are two type of settings. **User settings** & **Global Settings**. | ||
User settings is always bound to an entity (Generally for User Model) while global settings are not bound to any entity | ||
|
||
You can easily configure the settings type with `global` property in the settings class | ||
|
||
```php | ||
protected bool $global = false; | ||
``` | ||
<br> | ||
|
||
### 💠 Retrieving the settings | ||
|
||
```php | ||
use Visanduma\NovaSettings\NovaSettings; | ||
|
||
// getting single value | ||
NovaSettings::get('contact.name', 'default value'); | ||
|
||
nova_settings('contact.name','default value'); | ||
|
||
// getting whole settings array | ||
NovaSettings::get('contact'); | ||
|
||
nova_settings('contact'); | ||
|
||
|
||
// getting global settings | ||
NovaSettings::global('system.email'); | ||
|
||
NovaSettings::global('system'); | ||
|
||
nova_settings_global('system.phone'), | ||
``` | ||
<br> | ||
|
||
### 💠 Transforming inputs | ||
|
||
If you need to customize user-submitted form data, override the following method in the settings class. This method will receive form data array as its argument | ||
|
||
```php | ||
protected function transformInputs(array $inputs): array | ||
|
||
{ | ||
// do your modifications | ||
|
||
return $inputs; | ||
} | ||
``` | ||
<br> | ||
|
||
### 💠 Hooks | ||
|
||
```php | ||
protected function afterSaved(NovaRequest $request) | ||
|
||
{ | ||
// this method will be called after the form is saved | ||
} | ||
``` | ||
<br> | ||
|
||
### Known issues | ||
|
||
- File inputs does not work correctly | ||
- Uploaded files cannot be delete | ||
- Not works well with 3rd party fields | ||
|
||
### Todo | ||
- Authorization | ||
- Caching | ||
|
||
- [ ] Authorization | ||
- [ ] Caching | ||
- [ ] Events | ||
|
||
## Credits | ||
|
||
- [Visanduma](https://github.com/Visanduma) | ||
- [LaHiRu](https://github.com/lahirulhr) | ||
- [All Contributors](../../contributors) | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('advance_nova_settings', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('key'); | ||
$table->string('value')->nullable(); | ||
$table->nullableMorphs('owner'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('advance_nova_settings'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
/* Nova Tool CSS */ | ||
|
Oops, something went wrong.