Skip to content

Commit

Permalink
Add icon attribute to navbar element (Azuriom#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sloyni authored Sep 2, 2022
1 parent dabf2ec commit db773f3
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/Http/Requests/NavbarElementRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function rules()
{
return [
'name' => ['required', 'string', 'max:100'],
'icon' => ['nullable', 'string', 'max:100'],
'type' => ['string', Rule::in(NavbarElement::types())],
'link' => ['required_if:type,link', 'nullable', 'string', 'max:150'],
'plugin' => ['required_if:type,plugin', 'nullable', Rule::in(plugins()->getRouteDescriptions()->keys())],
Expand Down
12 changes: 10 additions & 2 deletions app/Models/NavbarElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/**
* @property int $id
* @property string $name
* @property string|null $icon
* @property string $value
* @property int $position
* @property string $type
Expand Down Expand Up @@ -50,7 +51,7 @@ class NavbarElement extends Model
* @var array
*/
protected $fillable = [
'name', 'value', 'position', 'type', 'parent_id', 'new_tab',
'name', 'icon', 'value', 'position', 'type', 'parent_id', 'new_tab',
];

/**
Expand Down Expand Up @@ -127,7 +128,14 @@ public function isCurrent()

public function getNameAttribute(string $value)
{
return new HtmlString($value);
$icon = $this->icon !== null ? '<i class="'.$this->icon.'"></i> ' : '';

return new HtmlString($icon.e($value));
}

public function rawName()
{
return $this->getRawOriginal('name');
}

public function getTypeValue(string $type)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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::table('navbar_elements', function (Blueprint $table) {
$table->string('icon')->nullable()->after('name');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('navbar_elements', function (Blueprint $table) {
$table->dropColumn('icon');
});
}
};
1 change: 1 addition & 0 deletions database/seeders/NavbarElementSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function run()
{
NavbarElement::firstOrCreate(['type' => 'home'], [
'name' => trans('seed.navbar.home'),
'icon' => 'bi bi-house',
'value' => '#',
]);
}
Expand Down
22 changes: 19 additions & 3 deletions resources/views/admin/navbar-elements/_form.blade.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
@csrf

<div class="row g-3">
<div class="mb-3 col-md-6">
<div class="mb-3 col-md-4">
<label class="form-label" for="nameInput">{{ trans('messages.fields.name') }}</label>
<input type="text" class="form-control @error('name') is-invalid @enderror" id="nameInput" name="name" value="{{ (string) old('name', $navbarElement->name ?? '') }}" required>
<input type="text" class="form-control @error('name') is-invalid @enderror" id="nameInput" name="name" value="{{ old('name', $navbarElement->rawName() ?? '') }}" required>

@error('name')
<span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
@enderror
</div>

<div class="mb-3 col-md-6">
<div class="mb-3 col-md-4">
<label class="form-label" for="iconInput">{{ trans('messages.fields.icon') }}</label>

<div class="input-group @error('icon') has-validation @enderror">
<span class="input-group-text"><i class="{{ $navbarElement->icon ?? 'bi bi-house' }}"></i></span>

<input type="text" class="form-control @error('icon') is-invalid @enderror" id="iconInput" name="icon" value="{{ old('icon', $navbarElement->icon ?? '') }}" placeholder="bi bi-house" aria-labelledby="iconLabel">

@error('icon')
<span class="invalid-feedback" role="alert"><strong>{{ $message }}</strong></span>
@enderror
</div>

<small id="iconLabel" class="form-text">@lang('messages.icons')</small>
</div>

<div class="mb-3 col-md-4">
<label class="form-label" for="typeSelect">{{ trans('messages.fields.type') }}</label>
<select class="form-select @error('type') is-invalid @enderror" id="typeSelect" name="type" required v-model="type">
@foreach($types as $type)
Expand Down

0 comments on commit db773f3

Please sign in to comment.