+# V 0.3.2 Phrase Word
+
+## Added
+- index.blade: "Neu"-Button in Übersicht
+- Word:
+ - Unique-Regel for "word"
+- Phrase:
+ - Unique-Regel für "phrase"
+
+## Changes
+- Phrase: Anlegen: Voreinstellung deutsch, OwnerId
+- Imperfekt -> Präteritum
+
# V 0.3.1 Note
## Added
namespace App\Http\Controllers;
+use App\Models\Phrase;
+use App\Helpers\Helper;
+use App\Helpers\DbHelper;
+use App\Models\SProperty;
+use App\Helpers\Pagination;
+use App\Helpers\ViewHelper;
use Illuminate\Http\Request;
+use Illuminate\Validation\Rule;
+use App\Helpers\ContextLaraKnife;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Validator;
-use App\Models\Phrase;
-use App\Models\SProperty;
-use App\Helpers\ContextLaraKnife;
-use App\Helpers\ViewHelper;
-use App\Helpers\DbHelper;
-use App\Helpers\Helper;
-use App\Helpers\Pagination;
+
+define('GERMAN', 1202);
class PhraseController extends Controller
{
if (count($fields) === 0) {
$fields = [
'phrase' => '',
- 'language_scope' => '',
+ 'language_scope' => GERMAN,
'word_id' => '',
'german_id' => '',
- 'owner_id' => '',
+ 'owner_id' => auth()->id(),
'verifiedby_id' => ''
];
}
- $optionsLanguage = SProperty::optionsByScope('language', $fields['language_scope'], '-');
- $optionsOwner = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['owner_id'], __('<Please select>'));
- $optionsVerifiedby = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['verifiedby_id'], __('<Please select>'));
+ $optionsLanguage = SProperty::optionsByScope('localization', $fields['language_scope'], '-');
$context = new ContextLaraKnife($request, $fields);
$rc = view('phrase.create', [
'context' => $context,
'optionsLanguage' => $optionsLanguage,
- 'optionsOwner' => $optionsOwner,
- 'optionsVerifiedby' => $optionsVerifiedby,
]);
}
return $rc;
* Returns the validation rules.
* @return array<string, string> The validation rules.
*/
- private function rules(bool $isCreate = false): array
+ private function rules(bool $isCreate = false, int $id=null): array
{
$rc = [
- 'phrase' => 'required',
- 'translation' => 'required',
];
if ($isCreate) {
- $rc['language'] = 'required';
+ $rc['language_scope'] = 'required';
+ $rc['phrase'] = 'required|unique:phrases';
+ } else {
+ $rc['phrase'] = ['required', Rule::unique('phrases')->ignore($id)];
}
return $rc;
}
{
Route::get('/phrase-index', [PhraseController::class, 'index'])->middleware('auth');
Route::post('/phrase-index', [PhraseController::class, 'index'])->middleware('auth');
- //Route::get('/phrase-create', [PhraseController::class, 'create'])->middleware('auth');
- //Route::put('/phrase-store', [PhraseController::class, 'store'])->middleware('auth');
+ Route::get('/phrase-create', [PhraseController::class, 'create'])->middleware('auth');
+ Route::put('/phrase-store', [PhraseController::class, 'store'])->middleware('auth');
Route::post('/phrase-edit/{phrase}', [PhraseController::class, 'edit'])->middleware('auth');
Route::get('/phrase-edit/{phrase}', [PhraseController::class, 'edit'])->middleware('auth');
Route::post('/phrase-update/{phrase}', [PhraseController::class, 'update'])->middleware('auth');
$rc = null;
if ($request->btnSubmit === 'btnStore') {
$fields = $request->all();
- $validator = Validator::make($fields, $this->rules(true));
+ $rules = $this->rules(true);
+ $validator = Validator::make($fields, $rules);
if ($validator->fails()) {
+ $errors = $validator->errors();
$rc = back()->withErrors($validator)->withInput();
} else {
$validated = $validator->validated();
$validated['phrase'] = strip_tags($validated['phrase']);
- $validated['translation'] = strip_tags($validated['translation']);
- Phrase::create($validated);
+ $phrase = Phrase::create($validated);
+ $rc = redirect("/phrase-edit/$phrase->id");
}
}
if ($rc == null) {
} elseif ($request->btnSubmit === 'btnStore') {
$id = $phrase->id;
$fields = $request->all();
- $validator = Validator::make($fields, $this->rules(false));
+ $validator = Validator::make($fields, $this->rules(false, $id));
if ($validator->fails()) {
$errors = $validator->errors();
$rc = back()->withErrors($validator)->withInput();
} else {
$validated = $validator->validated();
$validated['phrase'] = strip_tags($validated['phrase']);
- $validated['translation'] = strip_tags($validated['translation']);
+ $validated['translation'] = strip_tags($fields['translation']);
// Phrase has been changed?
$phraseDb = Phrase::find($id);
if ($phrase->phrase !== $phraseDb->phrase) {
use Illuminate\Http\Request;
use App\Helpers\StringHelper;
use App\Helpers\GermanGrammar;
+use Illuminate\Validation\Rule;
use App\Helpers\KeyValueStorage;
use App\Helpers\ViewHelperLocal;
use App\Helpers\ContextLaraKnife;
* Returns the validation rules.
* @return array<string, string> The validation rules.
*/
- private function rules(string $variant): array
+ private function rules(string $variant, ?Word $word = null): array
{
switch ($variant) {
+ case 'store':
+ $rc = ['word' => 'required|unique:words', 'wordtype_scope' => 'required'];
+ break;
case 'trans':
$rc = [
- 'word' => 'required',
+ 'word' => 'required|unique:words',
'usage' => 'required',
'verifiedby_id' => ''
];
+ if ($word == null) {
+ $rc['word'] = 'required|unique:words';
+ } else {
+ $rc['word'] = ['required', Rule::unique('words')->ignore($word->id)];
+ }
break;
case 'noun':
$rc = [
'c12' => 'required',
];
break;
- case 'adjective':
+ case 'adjective':
$rc = [
];
break;
$word = null;
if ($request->btnSubmit === 'btnStore') {
$fields = $request->all();
- $validator = Validator::make($fields, ['word' => 'required', 'wordtype_scope' => 'required']);
+ $rules = $this->rules('store');
+ $validator = Validator::make($fields, $rules);
if ($validator->fails()) {
$rc = $validator->errors();
$rc = back()->withErrors($validator)->withInput();
$rc = null;
$session = $request->session();
$id = $word->id;
- $validator = Validator::make($fields, $this->rules('trans'));
+ $validator = Validator::make($fields, $this->rules('trans', $word));
if ($validator->fails()) {
$errors = $validator->errors();
$rc = back()->withErrors($validator)->withInput();
"dist": {
"type": "path",
"url": "../laraknife",
- "reference": "542a161082cb090cb635241880b7fd56267d66d1"
+ "reference": "51702fba5a786ac71dd1628e7aee3aae747d6003"
},
"require-dev": {
"phpunit/phpunit": "11.0.x-dev"
},
{
"name": "psr/http-factory",
- "version": "1.0.2",
+ "version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-factory.git",
- "reference": "e616d01114759c4c489f93b099585439f795fe35"
+ "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35",
- "reference": "e616d01114759c4c489f93b099585439f795fe35",
+ "url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a",
+ "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a",
"shasum": ""
},
"require": {
- "php": ">=7.0.0",
+ "php": ">=7.1",
"psr/http-message": "^1.0 || ^2.0"
},
"type": "library",
"homepage": "https://www.php-fig.org/"
}
],
- "description": "Common interfaces for PSR-7 HTTP message factories",
+ "description": "PSR-17: Common interfaces for PSR-7 HTTP message factories",
"keywords": [
"factory",
"http",
"response"
],
"support": {
- "source": "https://github.com/php-fig/http-factory/tree/1.0.2"
+ "source": "https://github.com/php-fig/http-factory"
},
- "time": "2023-04-10T20:10:41+00:00"
+ "time": "2024-04-15T12:06:14+00:00"
},
{
"name": "psr/http-message",
"free text": "Freier Text",
"Genus": "Geschlecht",
"grammar rules": "Grammatikregeln",
-"Imperfect": "Imperfekt",
"masculine": "Maskulinum",
"neuter": "Neutrum",
"Not verified": "Nicht überprüft",
"Noun": "Nomen",
"Nouns": "Nomen",
"Participle": "Partizip",
+"Past tense": "Präteritum",
"Phrase": "Satz",
"Phrases": "Sätze",
"Preposition": "Präposition",
@method('PUT')
<x-laraknife.panels.create title="{{ __('Creation of a Phrase') }}">
<x-laraknife.forms.combobox position="alone" name="language_scope" label="Language" :options="$optionsLanguage" width2="4"/>
- <x-laraknife.forms.combobox position="alone" name="owner_id" label="Owner" :options="$optionsOwner" width2="4"/>
- <x-laraknife.forms.combobox position="alone" name="verifiedby_id" label="Verifiedby" :options="$optionsVerifiedby" width2="4"/>
- <x-laraknife.forms.text position="alone" name="phrase" label="Phrase" value="{{ $context->valueOf('phrase') }}" width2="4" rows="2" />
+ <x-laraknife.forms.text position="alone" name="phrase" label="Phrase" value="{{ $context->valueOf('phrase') }}" width2="10" rows="3" />
</x-laraknife.panels.create>
</form>
@extends('layouts.backend')
@section('content')
- <form id="phrase-edit" action="/phrase-update/{{ $context->model->id }}" method="POST">
+ <form id="phrase-edit" action="/phrase-update/{{ $context->model->id }}" method="POST">
@csrf
<input type="hidden" name="lastLanguage" value="{{ $context->valueOf('lastLanguage') }}">
<x-laraknife.panels.edit title="{{ __('Change of a Phrase') }}">
- <x-laraknife.forms.combobox position="alone" name="language" label="Language" :options="$optionsLanguage" width2="4" class="lkn-autoupdate"/>
- <x-laraknife.forms.text position="alone" name="phrase" label="Phrase" value="{{ $context->valueOf('phrase') }}" width2="10" rows="3" />
- <x-laraknife.forms.text position="alone" name="translation" label="Translation" value="{{ $context->valueOf('translation') }}" width2="10" rows="3" />
+ <x-laraknife.forms.text position="alone" name="phrase" label="Phrase" value="{{ $context->valueOf('phrase') }}"
+ width2="10" rows="3" />
+ <x-laraknife.forms.combobox position="alone" name="language" label="Language" :options="$optionsLanguage" width2="4"
+ class="lkn-autoupdate" />
+ <x-laraknife.forms.text position="alone" name="translation" label="Translation"
+ value="{{ $context->valueOf('translation') }}" width2="10" rows="3" />
</x-laraknife.panels.edit>
</form>
@endsection
<x-laraknife.forms.combobox position="last" name="verified" label="Verified" :options="$optionsVerified" class="lkn-autoupdate" width2="4" />
<x-laraknife.forms.string position="alone" name="text" label="Text" value="{{ $context->valueOf('text') }}" width2="4" />
</x-laraknife.panels.filter>
+ <x-laraknife.panels.index-button buttonType="new"/>
<x-laraknife.panels.sortable-table :context="$context" :pagination="$pagination">
<thead>
<tr>
value="{{ $context->valueOf('c5') }}" width1="1" width2="2" />
<x-laraknife.forms.string position="last" name="c6" label="Sie"
value="{{ $context->valueOf('c6') }}" width1="1" width2="2" />
- <x-laraknife.forms.string position="first" name="c7" label="Imperfekt Ich"
+ <x-laraknife.forms.string position="first" name="c7" label="Präteritum Ich"
value="{{ $context->valueOf('c7') }}" width2="2" />
<x-laraknife.forms.string position="middle" name="c8" label="Du"
value="{{ $context->valueOf('c8') }}" width1="1" width2="2" />
<x-laraknife.forms.string position="last" name="c9" label="Er/Sie/Es"
value="{{ $context->valueOf('c9') }}" width1="1" width2="2" />
- <x-laraknife.forms.string position="first" name="c10" label="Imperfekt Wir"
+ <x-laraknife.forms.string position="first" name="c10" label="Präteritum Wir"
value="{{ $context->valueOf('c10') }}" width2="2" />
<x-laraknife.forms.string position="middle" name="c11" label="Ihr"
value="{{ $context->valueOf('c11') }}" width1="1" width2="2" />