adding kwaadpepper enums
adding register mode setting providing app db settings in config() validating requirement/optionnality of registration field upon defined register mode
This commit is contained in:
parent
0deec3d68c
commit
b16c0e9128
10 changed files with 95 additions and 72 deletions
|
|
@ -2,11 +2,7 @@
|
|||
|
||||
namespace App\Enums;
|
||||
|
||||
/**
|
||||
* mini classe enum indépendante
|
||||
* de la dépendance
|
||||
* //use Kwaadpepper\Enum\BaseEnum;
|
||||
*/
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
/**
|
||||
* @method static self debug()
|
||||
|
|
@ -16,68 +12,6 @@ namespace App\Enums;
|
|||
* @method static self error()
|
||||
* @method static self critical()
|
||||
*/
|
||||
//final class LogType extends BaseEnum
|
||||
class LogType
|
||||
final class LogType extends BaseEnum
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string|int
|
||||
* @readonly
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/** @readonly */
|
||||
protected $label;
|
||||
|
||||
private static function makeElement($label, $value = null) {
|
||||
if ($value === null) {
|
||||
$value = $label;
|
||||
}
|
||||
$obj = new static();
|
||||
$obj->value = $value;
|
||||
$obj->label = $label;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return int|string
|
||||
*
|
||||
*/
|
||||
public function __get(string $name)
|
||||
{
|
||||
if ($name === 'label') {
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
if ($name === 'value') {
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
public static function debug() {
|
||||
return self::makeElement("debug");
|
||||
}
|
||||
|
||||
public static function log() {
|
||||
return self::makeElement("log");
|
||||
}
|
||||
|
||||
public static function warning() {
|
||||
return self::makeElement("warning");
|
||||
}
|
||||
|
||||
public static function info() {
|
||||
return self::makeElement("info");
|
||||
}
|
||||
|
||||
public static function error() {
|
||||
return self::makeElement("error");
|
||||
}
|
||||
|
||||
public static function critical() {
|
||||
return self::makeElement("critical");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
33
app/Enums/SettingRegisterMode.php
Normal file
33
app/Enums/SettingRegisterMode.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Kwaadpepper\Enum\BaseEnum;
|
||||
|
||||
/**
|
||||
* @method static self public()
|
||||
* @method static self salaries()
|
||||
*/
|
||||
final class SettingRegisterMode extends BaseEnum
|
||||
{
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
'public' => 'public',
|
||||
'salaries' => 'salaries',
|
||||
];
|
||||
}
|
||||
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
'public' => __('Public'),
|
||||
'salaries' => __('Salaries'),
|
||||
];
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return (string)$this->label;
|
||||
}
|
||||
}
|
||||
|
|
@ -35,10 +35,13 @@ class SettingsController extends Controller
|
|||
}
|
||||
|
||||
for($i = 0; $i < count($settings); $i++) {
|
||||
$settings[$i]->value = $request->input($settings[$i]->key) === null ? 0 : $request->input($settings[$i]->key);
|
||||
if(is_array($request->input($settings[$i]->key))) {
|
||||
$settings[$i]->value = implode(',', $request->input($settings[$i]->key));
|
||||
} else {
|
||||
$settings[$i]->value = $request->input($settings[$i]->key) === null ? 0 : $request->input($settings[$i]->key);
|
||||
}
|
||||
$settings[$i]->save();
|
||||
}
|
||||
|
||||
return redirect()->route('bo.settings')->with('success', 'Modifications enregistrés !');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use App\Models\Customers;
|
|||
use App\Models\Magasin;
|
||||
use App\Models\Order;
|
||||
use App\Models\PasswordReset;
|
||||
use App\Models\Setting;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
|
@ -27,6 +28,7 @@ class CustomerController extends Controller
|
|||
if (Auth::guard('customer')->check()) {
|
||||
return redirect()->route('home');
|
||||
}
|
||||
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace App\Http\Requests;
|
|||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use App\Rules\Adult;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CustomerRegisterRequest extends FormRequest
|
||||
{
|
||||
|
|
@ -25,7 +26,26 @@ class CustomerRegisterRequest extends FormRequest
|
|||
*/
|
||||
public function rules()
|
||||
{
|
||||
if(config('bosettings.register_salaries') && config('bosettings.register_public')) {
|
||||
$matriculeRule = 'nullable|exists:salaries,matricule';
|
||||
$codeRule = ['nullable',
|
||||
Rule::exists('salaries', 'code')
|
||||
->where('matricule', data_get($this->all(), 'matricule'))
|
||||
];
|
||||
} elseif (config('bosettings.register_salaries') && !config('bosettings.register_public')) {
|
||||
$matriculeRule = 'required|exists:salaries,matricule';
|
||||
$codeRule = ['required',
|
||||
Rule::exists('salaries', 'code')
|
||||
->where('matricule', data_get($this->all(), 'matricule'))
|
||||
];
|
||||
} else {
|
||||
$matriculeRule = 'sometimes';
|
||||
$codeRule = 'sometimes';
|
||||
}
|
||||
|
||||
return [
|
||||
'matricule' => $matriculeRule,
|
||||
'code' => $codeRule,
|
||||
'lastname' => 'required|string|max:255',
|
||||
'firstname' => 'required|string|max:255',
|
||||
'phone' => 'sometimes|max:255',
|
||||
|
|
|
|||
|
|
@ -39,6 +39,16 @@ class AppServiceProvider extends ServiceProvider
|
|||
setlocale(LC_TIME, strtoupper(config('app.locale')) . "_" . config('app.locale') . '.utf8');
|
||||
}
|
||||
|
||||
//bo settings as config
|
||||
config([
|
||||
'bosettings' => Setting::all()
|
||||
->keyBy('key') // key every setting by its name
|
||||
->transform(function ($setting) {
|
||||
return $setting->value; // return only the value
|
||||
})
|
||||
->toArray() // make it an array
|
||||
]);
|
||||
|
||||
//this is useful when setting up the app whene ranges table doesn't exist yet
|
||||
try {
|
||||
// on partage les ranges (gammes produit)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
"fideloper/proxy": "^4.4",
|
||||
"fruitcake/laravel-cors": "^2.0",
|
||||
"guzzlehttp/guzzle": "^7.0.1",
|
||||
"kwaadpepper/enum": "^0.1.3",
|
||||
"kwaadpepper/enum": "^0.1.4",
|
||||
"laravel/framework": "^8.12",
|
||||
"laravel/tinker": "^2.5",
|
||||
"spatie/laravel-sitemap": "^5.8"
|
||||
|
|
|
|||
2
composer.lock
generated
2
composer.lock
generated
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "b28ee503421668121a44e5e711c9b199",
|
||||
"content-hash": "87c02043e13235111043042aabbfc13f",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asm89/stack-cors",
|
||||
|
|
|
|||
|
|
@ -240,6 +240,8 @@ return [
|
|||
'Validator' => Illuminate\Support\Facades\Validator::class,
|
||||
'View' => Illuminate\Support\Facades\View::class,
|
||||
//Enums
|
||||
'LogType' => \App\Enums\LogType::class,
|
||||
'SettingRegisterMode' => \App\Enums\SettingRegisterMode::class,
|
||||
],
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -66,5 +66,24 @@
|
|||
<small class="text-muted">Information lorsqu'un client valide une commande</small>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
Mode d'inscription
|
||||
@foreach(SettingRegisterMode::toArray() as $registermode)
|
||||
@if ($loop->first)
|
||||
<div class="form-row">
|
||||
@endif
|
||||
<label class="col-form-label">
|
||||
<input type="checkbox" name="register_{{ $registermode->value }}" value="{{ $registermode->value }}" @if(($settingsToPrint['register_'.$registermode->value]??'')==$registermode->value)checked @endif>
|
||||
{{ $registermode->label }}
|
||||
<small class="text-muted"></small>
|
||||
</label>
|
||||
@if($loop->last)
|
||||
</div>
|
||||
@else
|
||||
</div>
|
||||
<div class="form-row">
|
||||
@endif
|
||||
@endforeach
|
||||
</div>
|
||||
</form>
|
||||
@endsection
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue