1. 3 Xử lý logic làm giao diện (ok)
Previous1. 2 Xây dựng giao diện settings (ok)Next1. 4 Thiết kế database ánh xạ với front-end && function setting 😎(ok)
Last updated
Last updated
C:\xampp82\htdocs\lva7\config\setting_fields.php
<?php
return [
'app' => [
'title' => 'General',
'icon' => 'fas fa-cube',
'desc' => 'All the general settings for application.',
'elements' => [
[
'type' => 'text', // input fields type
'name' => 'app_name', // unique name for field
'label' => 'App Name', // you know what label it is
'class' => '', // any class for input
'rules' => 'required|min:2|max:50', // validation rule of laravel
'value' => 'Laravel Starter' // default value if you want
]
]
],
];
C:\xampp82\htdocs\lva7\resources\views\backend\settings\index.blade.php
@extends('backend.layouts.app')
@section('title')
@lang('Dashboard')
@endsection
@section('breadcrumbs')
<x-backend-breadcrumbs>
<x-backend-breadcrumb-item
type="active"
icon='fas fa-cogs'
>Settings</x-backend-breadcrumb-item>
</x-backend-breadcrumbs>
@endsection
@section('content')
<div class="card mb-4">
<div class="card-body">
<p>section-header</p>
<!-- Dashboard Content Area -->
<div class="row mt-4">
<div class="col">
<form
method="post"
action="{{ route('backend.settings.store') }}"
class="form-horizontal"
role="form"
>
@csrf
@if (count(config('setting_fields', [])))
@foreach (config('setting_fields') as $section => $fields)
<div class="card card-accent-primary mb-4">
<div class="card-header">
<i class="{{ Arr::get($fields,'icon','fas fa-cube') }}"></i> {{ $fields['title'] }}
</div>
<div class="card-body">
<p class="text-muted">{{ $fields['desc'] }}</p>
<div class="row mb-3">
<div class="col">
@foreach($fields['elements'] as $field)
@includeIf('backend.settings.fields.' . $field['type'] )
@endforeach
</div>
</div>
</div>
</div>
@endforeach
@endif
<div class="row m-b-md">
<div class="col-md-12">
<button class="btn-primary btn">
<i class="fas fa-save"></i> Save </button>
</div>
</div>
</form>
</div>
</div>
<!-- /.row-->
<!-- / Dashboard Content Area -->
</div>
</div>
@endsection
C:\xampp82\htdocs\lva7\resources\views\backend\settings\fields\text.blade.php
@php
$required = Str::contains($field['rules'], 'required') ? 'required' : '';
$required_mark = $required != '' ? '<span class="text-danger"> <strong>*</strong> </span>' : '';
@endphp
<div class="form-group mb-3">
<label
for="{{ $field['name'] }}"
class="form-label"
> <strong>{{ $field['label'] }}</strong> ({{ $field['name'] }})</label> <span class="text-danger"> <strong>*</strong> </span>
<input
type="{{ $field['type'] }}"
name="{{ $field['name'] }}"
value="{{ old($field['name'], $field['value']) }}"
class="form-control {{ Arr::get($field, 'class') }} {{ $errors->has($field['name']) ? ' is-invalid' : '' }}"
id="{{ $field['name'] }}"
placeholder="{{ $field['label'] }}"
{{ $required }}
>
@if ($errors->has($field['name']))
<small class="invalid-feedback">{{ $errors->first($field['name']) }}</small>
@endif
</div>
C:\xampp82\htdocs\lva7\config\setting_fields.php
<?php
return [
'app' => [
'title' => 'General',
'icon' => 'fas fa-cube',
'desc' => 'All the general settings for application.',
'elements' => [
[
'type' => 'text', // input fields type
'name' => 'app_name', // unique name for field
'label' => 'App Name', // you know what label it is
'class' => '', // any class for input
'rules' => 'required|min:2|max:50', // validation rule of laravel
'value' => 'Laravel Starter' // default value if you want
],
[
'type' => 'text', // input fields type
'name' => 'footer_text', // unique name for field
'label' => 'Footer Text', // you know what label it is
'class' => '', // any class for input
'rules' => 'required|min:2', // validation rule of laravel
'value' => '<a href="#" class="text-muted">Built with ♥ from Bangladesh</a>' // default value if you want
],
]
],
];