LaraKnife Kochbuch: Unterschied zwischen den Versionen

Aus Vokabulabor
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Zeile 46: Zeile 46:
**** <code>ViewHelper::addConditionComparism($conditions, $parameters, 'category_scope', 'category');</code>
**** <code>ViewHelper::addConditionComparism($conditions, $parameters, 'category_scope', 'category');</code>
**** <code>$optionsCategory = SProperty::optionsByScope('category', $fields['category'], 'all');</code>
**** <code>$optionsCategory = SProperty::optionsByScope('category', $fields['category'], 'all');</code>
**** <code>return view('note.index', [... optionsCategory ... ]);
**** <code>return view('note.index', [... optionsCategory ... ]);</code>
 
= Registerblatt-Seite =
 
* Controller.edit()
<syntaxhighlight lang="php">
$context = new ContextLaraKnife($request, null, $note);
$navigationTabInfo = ViewHelperLocal::getNavigationTabInfo('note-edit', 0, $note->id);
$rc = view('note.edit', [
  'context' => $context,
...
  'navTabsInfo' => $navigationTabInfo
]);
</syntaxhighlight>
 
* view/note/edit.blade.php
<pre>
@extends('layouts.backend')
 
@section('content')
    <form id="note-edit" action="/note-update/{{ $context->model->id }}" method="POST">
        @csrf
        <x-laraknife.panels.standard title="{{ __('Change of a Note') }}" fieldset="false">
            <x-laraknife.layout.nav-tabs :info="$navTabsInfo" fieldset="true">
                <x-laraknife.forms.combobox position="first" name="category_scope" label="Category" :options="$optionsCategory"
                    value="{{ $context->valueOf('category_scope') }}" width2="4" />
...
            </x-laraknife.layout.nav-tabs>
        </x-laraknife.panels.edit>
    </form>
@endsection
</pre>
 
* ViewHelperLocal.php:
<syntaxhighlight lang="php">
public static function getNavigationTabInfo(string $name, int $indexActive,
  int $referenceId = 0): ?NavigationTabs
{
  $rc = null;
  switch ($name) {
    case 'note-edit':
        $rc = new NavigationTabs(["Properties;/note-edit/$referenceId",
            "Documents;/note-index_documents/$referenceId"
        ], $indexActive);
        break;
      default:
        break;
  }
  return $rc;
}
</syntaxhighlight>

Version vom 30. April 2024, 09:11 Uhr

Links

Laraknife

Zielsetzung

Kleine Tipps zur Verwendung von LaraKnife.

Moduländerungen

In den Beispielen wird das Modul Notes verwendet.

Zusätzliches Attribut

Es soll das Attribut "info" ergänzt werden:

Zu tun:

  • Datenbank erweitern:
php artisan make:migration add_notes_info --table=notes

Die entstehende Datei bearbeiten:

public function up()
{
    Schema::table('notes', function ($table) {
        $table->string("info");
    });
}
php artisan migrate
  • Model erweitern:
    • app/Models/Note.php: in $fillable eintragen
  • Views erweitern:
    • Feld eventuell in index.blade.php eintragen
    • Feld in create.blade.php eintragen
    • Feld in edit.blade.php eintragen
    • Feld in show.blade.php eintragen
  • NoteController anpassen:
    • function create() und edit() und show(): ... $fields = [ ... 'info' => ...];
    • function index():
      • Wenn ein Filter dazukommt: $fields = [ ... 'info' => ...]
      • Wenn bei einem gemeinsamen Suchfilter auch diese Spalte durchsucht werden soll:
        • ViewHelper::addConditionPattern($conditions, $parameters, 'title,body,info,', 'text');
      • Wenn ein Combobox als Filter dazukommt:
        • ViewHelper::addConditionComparism($conditions, $parameters, 'category_scope', 'category');
        • $optionsCategory = SProperty::optionsByScope('category', $fields['category'], 'all');
        • return view('note.index', [... optionsCategory ... ]);

Registerblatt-Seite

  • Controller.edit()
$context = new ContextLaraKnife($request, null, $note);
$navigationTabInfo = ViewHelperLocal::getNavigationTabInfo('note-edit', 0, $note->id);
$rc = view('note.edit', [
  'context' => $context,
...
  'navTabsInfo' => $navigationTabInfo
]);
  • view/note/edit.blade.php
@extends('layouts.backend')

@section('content')
    <form id="note-edit" action="/note-update/{{ $context->model->id }}" method="POST">
        @csrf
        <x-laraknife.panels.standard title="{{ __('Change of a Note') }}" fieldset="false">
            <x-laraknife.layout.nav-tabs :info="$navTabsInfo" fieldset="true">
                <x-laraknife.forms.combobox position="first" name="category_scope" label="Category" :options="$optionsCategory"
                    value="{{ $context->valueOf('category_scope') }}" width2="4" />
...
            </x-laraknife.layout.nav-tabs>
        </x-laraknife.panels.edit>
    </form>
@endsection
  • ViewHelperLocal.php:
public static function getNavigationTabInfo(string $name, int $indexActive, 
  int $referenceId = 0): ?NavigationTabs
{
  $rc = null;
  switch ($name) {
     case 'note-edit':
        $rc = new NavigationTabs(["Properties;/note-edit/$referenceId",
            "Documents;/note-index_documents/$referenceId"
        ], $indexActive);
        break;
      default:
        break;
  }
  return $rc;
}