Taskx mittels Laraknife: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Zeile 265: | Zeile 265: | ||
== Controller und Views anpassen == | == Controller und Views anpassen == | ||
=== Übersicht (index) === | |||
* Datei app/Http/Controllers/NoteController.php | * Datei app/Http/Controllers/NoteController.php | ||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
Zeile 272: | Zeile 273: | ||
return redirect('/note-create'); | return redirect('/note-create'); | ||
} else { | } else { | ||
$sql = 'SELECT title, body, user_id, cast(body AS VARCHAR(60)) as body2 FROM notes'; | $sql = 'SELECT id, title, body, user_id, cast(body AS VARCHAR(60)) as body2 FROM notes'; | ||
$userId = auth()->id(); | $userId = auth()->id(); | ||
$parameters = [':user_id' => $userId]; | $parameters = [':user_id' => $userId]; | ||
Zeile 299: | Zeile 300: | ||
* Datei resources/views/note/index.blade.php | * Datei resources/views/note/index.blade.php | ||
<syntaxhighlight lang="html"> | <syntaxhighlight lang="html"> | ||
form id="note-index" action="/note-index" method="POST"> | <form id="note-index" action="/note-index" method="POST"> | ||
@csrf | @csrf | ||
<x-laraknife.index-panel title="{{ __('Notes') }}"> | <x-laraknife.index-panel title="{{ __('Notes') }}"> | ||
Zeile 310: | Zeile 311: | ||
<tr> | <tr> | ||
<th></th> | <th></th> | ||
<th sortId="id">{{__('Id')}}</th> | |||
<th sortId="title">{{__('Title')}}</th> | <th sortId="title">{{__('Title')}}</th> | ||
<th sortId="body">{{__('Body')}}</th> | <th sortId="body">{{__('Body')}}</th> | ||
Zeile 319: | Zeile 321: | ||
<tr> | <tr> | ||
<td><a href="/note-edit/{{$note->id}}">{{ __('Change')}}</a></td> | <td><a href="/note-edit/{{$note->id}}">{{ __('Change')}}</a></td> | ||
<td>{{$note->id}}</td> | |||
<td>{{$note->title}}</td> | <td>{{$note->title}}</td> | ||
<td>{{$note->body2}}</td> | <td>{{$note->body2}}</td> | ||
<td><a href="/note-delete/{{$note->id}}">{{ __('Delete')}}</a></td> | <td><a href="/note-delete/{{$note->id}}">{{ __('Delete')}}</a></td> | ||
</tr> | </tr> | ||
Zeile 330: | Zeile 330: | ||
</x-laraknife.sortable-table-panel> | </x-laraknife.sortable-table-panel> | ||
</x-laraknife.index-panel> | </x-laraknife.index-panel> | ||
</form> | </syntaxhighlight> | ||
=== Anlegen (create) === | |||
* Datei app/Http/Controllers/NoteController.php | |||
<syntaxhighlight lang="php"> | |||
public function create(Request $request) | |||
{ | |||
if (array_key_exists('btnSubmit', $_POST) && $_POST['btnSubmit'] === 'btnCancel') { | |||
$rc = redirect('/note-index'); | |||
} else { | |||
$rc = null; | |||
$error = null; | |||
if (count($_POST) > 0) { | |||
$fields = $_POST; | |||
try { | |||
$incomingFields = $request->validate($this->rules(true)); | |||
$rc = $this->store($request); | |||
} catch (\Exception $e) { | |||
$error = $e->getMessage(); | |||
} | |||
} else { | |||
$fields = [ | |||
'title' => '', | |||
'body' => '', | |||
'category_id' => '2001', | |||
'status_id' => '2601', | |||
'group_id' => '2501', | |||
]; | |||
} | |||
if ($rc == null) { | |||
$optionsCategory = SProperty::optionsByScope('category', $fields['category_id'], '-'); | |||
$optionsStatus = SProperty::optionsByScope('notestatus', $fields['status_id'], '-'); | |||
$optionsGroup = SProperty::optionsByScope('group', $fields['group_id'], '-'); | |||
$rc = view('note.create', ['fields' => $fields, | |||
'optionsCategory' => $optionsCategory, | |||
'optionsStatus' => $optionsStatus, | |||
'optionsGroup' => $optionsGroup, | |||
'error' => $error]); | |||
} | |||
} | |||
return $rc; | |||
} | |||
private function rules(bool $isCreation=false): array | |||
{ | |||
$rc = [ | |||
'title' => 'required', | |||
'body' => 'required', | |||
'category_id' => 'required', | |||
'status_id' => 'required', | |||
'group_id' => 'required', | |||
]; | |||
return $rc; | |||
} | |||
public function store(Request $request) | |||
{ | |||
if ($request->btnSubmit === 'btnStore') { | |||
$incomingFields = $request->validate($this->rules()); | |||
$incomingFields['user_id'] = auth()->id(); | |||
$incomingFields['title'] = strip_tags($incomingFields['title']); | |||
$incomingFields['body'] = strip_tags($incomingFields['body']); | |||
Note::create($incomingFields); | |||
} | |||
return redirect('/note-index'); | |||
} | |||
</syntaxhighlight> | |||
* Datei resources/views/note/create.blade.php | |||
<syntaxhighlight lang="html"> | |||
<form id="note-create" action="/note-create" method="POST"> | |||
@csrf | |||
<x-laraknife.create-panel title="{{ __('Creation of a Note') }}" error="{{$error}}"> | |||
<x-laraknife.combobox position="first" name="status_id" label="Status" value="{{$fields['status_id']}}" :options="$optionsStatus" width2="4" /> | |||
<x-laraknife.combobox position="last" name="group_id" label="Group" value="{{$fields['group_id']}}" :options="$optionsGroup" width2="4" /> | |||
<x-laraknife.combobox position="alone" name="category_id" label="Category" value="{{$fields['category_id']}}" :options="$optionsCategory" width2="4" /> | |||
<x-laraknife.text position="alone" name="title" label="Title" value="{{$fields['title']}}" /> | |||
<x-laraknife.bigtext position="alone" name="body" label="Body" value="{{$fields['body']}}" rows="10" /> | |||
</x-laraknife.create-panel> | |||
</form> | |||
</syntaxhighlight> | |||
=== Ändern (edit) === | |||
* Datei app/Http/Controllers/NoteController.php | |||
<syntaxhighlight lang="php"> | |||
public function edit(Note $note) | |||
{ | |||
if (array_key_exists('btnSubmit', $_POST) && $_POST['btnSubmit'] === 'btnCancel') { | |||
$rc = redirect('/note-index'); | |||
} else { | |||
$optionsCategory = SProperty::optionsByScope('category', $note->category_id, '-'); | |||
$optionsStatus = SProperty::optionsByScope('notestatus', $note->status_id, '-'); | |||
$optionsGroup = SProperty::optionsByScope('group', $note->group_id, '-'); | |||
$rc = view('note.edit', [ | |||
'note' => $note, | |||
'optionsCategory' => $optionsCategory, | |||
'optionsStatus' => $optionsStatus, | |||
'optionsGroup' => $optionsGroup, | |||
]); | |||
} | |||
return $rc; | |||
} | |||
</syntaxhighlight> | |||
* Datei resources/views/note/edit.blade.php | |||
<syntaxhighlight lang="html"> | |||
<form id="note-edit" action="/note-update/{{ $note->id }}" method="POST"> | |||
@csrf | |||
<x-laraknife.edit-panel title="{{ __('Change of a Note') }}"> | |||
<x-laraknife.combobox position="first" name="status_id" label="Status" value="{{$note->status_id}}" :options="$optionsStatus" width2="4" /> | |||
<x-laraknife.combobox position="last" name="group_id" label="Group" value="{{$note->group_id}}" :options="$optionsGroup" width2="4" /> | |||
<x-laraknife.combobox position="alone" name="category_id" label="Category" value="{{$note->category_id}}" :options="$optionsCategory" width2="4" /> | |||
<x-laraknife.text position="alone" name="title" label="Title" value="{{$note->title}}" /> | |||
<x-laraknife.bigtext position="alone" name="body" label="Body" value="{{$note->body}}" rows="10" /> | |||
</x-laraknife.edit-panel> | |||
</form> | |||
</syntaxhighlight> | |||
=== Anzeigen (show/delete) === | |||
* Datei app/Http/Controllers/NoteController.php | |||
<syntaxhighlight lang="php"> | |||
public function show(Note $note) | |||
{ | |||
if (array_key_exists('btnSubmit', $_POST) && $_POST['btnSubmit'] === 'btnCancel') { | |||
$rc = redirect('/note-index'); | |||
} else { | |||
$optionsCategory = SProperty::optionsByScope('category', 'category', ''); | |||
$optionsGroup = SProperty::optionsByScope('group', 'group', ''); | |||
$optionsStatus = SProperty::optionsByScope('notestatus', 'status', ''); | |||
$rc = view('note.show', [ | |||
'note' => $note, | |||
'optionsCategory' => $optionsCategory, | |||
'optionsGroup' => $optionsGroup, | |||
'optionsStatus' => $optionsStatus, | |||
'mode' => 'delete' | |||
]); | |||
} | |||
return $rc; | |||
} | |||
</syntaxhighlight> | |||
* Datei resources/views/note/show.blade.php | |||
<syntaxhighlight lang="html"> | |||
<form id="note-show" action="/note-show/{{ $note->id }}/{{ $mode }}" method="POST"> | |||
@csrf | |||
@if ($mode === 'delete') | |||
@method('DELETE') | |||
@endif | |||
<x-laraknife.show-panel title="{{ __($mode !== 'delete' ? 'A Note' : 'Deletion of a Note') }}" | |||
mode="{{ $mode }}"> | |||
<x-laraknife.combobox position="first" name="status_id" label="Status" value="{{ $note->status_id }}" | |||
:options="$optionsStatus" width2="4" attribute="readonly" /> | |||
<x-laraknife.combobox position="last" name="group_id" label="Group" value="{{ $note->group_id }}" | |||
:options="$optionsGroup" width2="4" attribute="readonly" /> | |||
<x-laraknife.combobox position="first" name="category_id" label="Category" value="{{ $note->category_id }}" | |||
:options="$optionsCategory" width2="4" attribute="readonly" /> | |||
<x-laraknife.text position="last" name="id" label="Id" value="{{ $note->id }}" width2="4" | |||
attribute="readonly" /> | |||
<x-laraknife.text position="alone" name="title" label="Title" value="{{ $note->title }}" | |||
attribute="readonly" /> | |||
<x-laraknife.bigtext position="alone" name="body" label="Body" value="{{ $note->body }}" rows="10" | |||
attribute="readonly" /> | |||
</x-laraknife.show-panel> | |||
</form> | |||
</syntaxhighlight> | </syntaxhighlight> |
Version vom 30. Dezember 2023, 22:33 Uhr
Links
Zielsetzung
Es soll eine minimale Web-Applikation mit den Werkzeugen Laravel und Laraknife erstellt werden: Eine Verwaltung von Notizen.
Name
Eine Verballhornung des Wortes "Tasks": Die schwäbische Aussprache spricht ein x am Ende.
Eigenschaften
- Benutzerverwaltung: nur angemeldete Benutzer können Applikation nutzen
- Rechteverwaltung mittels Rollen
- Verwaltung von Notizen: Titel, Text, Kategorie, Text, Status: offen, erledigt
Installation
- als normaler Benutzer (nicht root):
sudo apt install php-laravel-framework npm php-intl
PROJ=taskx
PASSW=topsecret
BASE=/home/ws/php/$PROJ
cd $(dirname $BASE)
composer create-project laravel/laravel $PROJ
cd $BASE
composer require laravel/ui
composer require spatie/laravel-permission
php artisan ui bootstrap --auth
dbtool create-db-and-user lrv$PROJ $PROJ "$PASSW"
sed -i -e "s/DB_DATABASE=.*/DB_DATABASE=lrv$PROJ/" \
-e "s/DB_USERNAME=.*/DB_USERNAME=$PROJ/" \
-e "s/DB_PASSWORD=.*/DB_PASSWORD=$PASSW/" .env
M_HOST=mail.gmx.net
M_PORT=587
M_USER=example@gmx.de
M_PW=Top.Secret42
sed -i \
-e "s/APP_NAME=.*/APP_NAME=$PROJ"/ \
-e "s/MAIL_MAILER=.*/MAIL_MAILER=smtp/" \
-e "s/MAIL_HOST=.*/MAIL_HOST=$M_HOST/" \
-e "s/MAIL_PORT=.*/MAIL_PORT=$M_PORT/" \
-e "s/MAIL_USERNAME=.*/MAIL_USERNAME=$M_USER/" \
-e "s/MAIL_PASSWORD=.*/MAIL_PASSWORD=$M_PW/" \
-e "s/MAIL_ENCRYPTION=.*/MAIL_ENCRYPTION=STARTTLS/" \
-e "s/MAIL_FROM_ADDRESS=.*/MAIL_FROM_ADDRESS=\"$M_USER\"/" .env
sudo sed -i -e "3 i 127.0.0.1 $PROJ.test" /etc/hosts
grep "$PROJ.test" /etc/hosts
php artisan migrate
npm install
npm run dev
# Abbruch mit Strg-C
Einrichten LaraKnife
composer config repositories.laraknife vcs https://github.com/hamatoma/laraknife
# Branch main:
composer require hamatoma/laraknife:dev-main
composer update
vendor/hamatoma/laraknife/scripts/laraknife-tool.sh build-links
Mehrsprachigkeit (I18N)
- config/app.php
'locale' => 'de_DE', 'available_locales' => [ 'English' => 'en', 'German' => 'de_DE', ],
- Übersetzungen aus LaraKnife aktivieren:
./Join
- Die neuen Wörter müssen in /resources/lang/sources/taskx.json eingetragen werden.
Starten Webserver
php artisan serve
- Im Browser: http://localhost:8000
Roles und SProperties füllen
sudo mysql lrv$PROJ <<'EOS'
insert into roles (name, priority, created_at, updated_at) values
('Administrator', 10, '2023.12.28', '2023-12-28'),
('Manager', 20, '2023.12.28', '2023-12-28'),
('User', 30, '2023.12.28', '2023-12-28'),
('Guest', 90, '2023.12.28', '2023-12-28');
insert into sproperties (id, scope, name, `order`, shortname, created_at) values
(1001, 'status', 'active', 10, 'A', '2023-12-28'),
(1002, 'status', 'inactive', 20, 'I', '2023-12-28'),
(2001, 'category', 'undefined', 10, '-', '2023-12-28'),
(2002, 'category', 'private', 20, 'P', '2023-12-28'),
(2003, 'category', 'work', 30, 'W', '2023-12-28'),
(2501, 'group', 'undefined', 10, '-', '2023-12-28'),
(2502, 'group', 'private', 20, 'P', '2023-12-28'),
(2503, 'group', 'work', 20, 'W', '2023-12-28'),
(2601, 'notestatus', 'open', 10, 'O', '2023-12-28'),
(2602, 'notestatus', 'closed', 20, 'C', '2023-12-28');
EOS
User anpassen
- Datei app/Models/User.php ergänzen:
protected $fillable = [ 'name', 'email', 'password', 'user_id', // <==== ];
Modul Notes erstellen
Tabellenbeschreibung erstellen
- Konvention: Tabelle wird kleingeschrieben, im Plural
TABLE=notes
php artisan make:migration create_${TABLE}_table
- Es wird die Datei database/migrations/2023_12_29_180821_create_notes_table.php erzeugt
- Diese Datei anpassen:
Schema::create('notes', function (Blueprint $table) { $table->id(); $table->timestamps(); $table->string('title'); $table->text('body'); // foreign key of sproperties. $table->integer('category_id'); // foreign key of sproperties. $table->integer('status_id'); // foreign key of sproperties. $table->integer('group_id'); $table->foreignId('user_id')->references('id')->on('users')->nullable(); });
Modul erzeugen
php artisan migrate
./Lara create:module database/migrations/2023_12_29_180821_create_notes_table.php
Layout erstellen
- Datei resources/views/layouts/taskx.blade.php erstellen:
<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Fonts -->
<!-- link rel="dns-prefetch" href="//fonts.bunny.net">
<link href="https://fonts.bunny.net/css?family=Nunito" rel="stylesheet" -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Scripts -->
@vite(['resources/sass/app.scss', 'resources/js/app.js'])
<link href="/css/laraknife.css" rel="stylesheet">
<link href="/css/langutor.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.bundle.min.js"></script>
<script src="/js/laraknife.js"></script>
</head>
<body>
<header>
<nav class="navbar navbar-expand-md bg-primary ">
<a class="navbar-brand" href="/home">Booking</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTop">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Start</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/user-edit">{{ __('Settings') }}</a>
</li>
<li>
<a class="nav-link" href="/public/doc/Impressum.pdf" target="_blank">{{ __('Imprint') }}</a>
</li>
<li>
<a class="nav-link" href="/public/doc/Datenschutz.pdf" target="_blank">{{ __('Privacy') }}</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0" action="/logout" method="post">
<button class="btn btn-outline-success my-2 my-sm-0 logout" name="btnLogout"
type="submit"> {{ __('Logout') }}</button>
</form>
</div>
</nav>
</header>
@yield('content')
</body>
</html>
cd resources/views/layouts
ln -s taskx.blade.php backend.blade.php
cd ../..
Homepage einrichten
- Datei resources/views/home.blade.php
@extends('layouts.taskx')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Dashboard') }}</div>
<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
{{ __('You are logged in!') }}
<ul>
<li><a href="/sproperty-index">SProperties</a></li>
<li><a href="/user-index">Benutzer</a></li>
<li><a href="/role-index">Rollen</a></li>
<li><a href="/notes-index">Notizen</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
@endsection
Routing einrichten
- In Datei routes/web.php einfügen:
SPropertyController::routes();
RoleController::routes();
UserController::routes();
NoteController::routes();
Starten, Registrieren, Login
- Den Webserver starten:
php artisan serve
- Im Brower aufrufen: http://localhost:8000
- Oben rechts: Register
- Felder ausfüllen
- Oben rechts: Login
Controller und Views anpassen
Übersicht (index)
- Datei app/Http/Controllers/NoteController.php
public function index()
{
if (array_key_exists('btnSubmit', $_POST) && $_POST['btnSubmit'] === 'btnNew') {
return redirect('/note-create');
} else {
$sql = 'SELECT id, title, body, user_id, cast(body AS VARCHAR(60)) as body2 FROM notes';
$userId = auth()->id();
$parameters = [':user_id' => $userId];
$conditions = ['user_id = :user_id'];
if (count($_POST) == 0) {
$fields = [
'text' => '',
'_sortParams' => 'id:desc'
];
} else {
$fields = $_POST;
ViewHelper::addConditionPattern($conditions, $parameters, 'title,body', 'text');
}
$sql = DbHelper::addConditions($sql, $conditions);
$sql = DbHelper::addOrderBy($sql, $fields['_sortParams']);
$records = DB::select($sql, $parameters);
$pagination = new Pagination($sql, $parameters, $fields);
return view('note.index', [
'records' => $records,
'fields' => $fields,
'pagination' => $pagination
]);
}
}
- Datei resources/views/note/index.blade.php
<form id="note-index" action="/note-index" method="POST">
@csrf
<x-laraknife.index-panel title="{{ __('Notes') }}">
<x-laraknife.filter-panel legend="{{ $pagination->legendText() }}">
<x-laraknife.text position="alone" name="text" label="Text" value="{{$fields['text']}}" width2="4" />
</x-laraknife.filter-panel>
<x-laraknife.index-button-panel buttonType="new"/>
<x-laraknife.sortable-table-panel :fields="$fields" :pagination="$pagination">
<thead>
<tr>
<th></th>
<th sortId="id">{{__('Id')}}</th>
<th sortId="title">{{__('Title')}}</th>
<th sortId="body">{{__('Body')}}</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach ($records as $note)
<tr>
<td><a href="/note-edit/{{$note->id}}">{{ __('Change')}}</a></td>
<td>{{$note->id}}</td>
<td>{{$note->title}}</td>
<td>{{$note->body2}}</td>
<td><a href="/note-delete/{{$note->id}}">{{ __('Delete')}}</a></td>
</tr>
@endforeach
</tbody>
</x-laraknife.sortable-table-panel>
</x-laraknife.index-panel>
Anlegen (create)
- Datei app/Http/Controllers/NoteController.php
public function create(Request $request)
{
if (array_key_exists('btnSubmit', $_POST) && $_POST['btnSubmit'] === 'btnCancel') {
$rc = redirect('/note-index');
} else {
$rc = null;
$error = null;
if (count($_POST) > 0) {
$fields = $_POST;
try {
$incomingFields = $request->validate($this->rules(true));
$rc = $this->store($request);
} catch (\Exception $e) {
$error = $e->getMessage();
}
} else {
$fields = [
'title' => '',
'body' => '',
'category_id' => '2001',
'status_id' => '2601',
'group_id' => '2501',
];
}
if ($rc == null) {
$optionsCategory = SProperty::optionsByScope('category', $fields['category_id'], '-');
$optionsStatus = SProperty::optionsByScope('notestatus', $fields['status_id'], '-');
$optionsGroup = SProperty::optionsByScope('group', $fields['group_id'], '-');
$rc = view('note.create', ['fields' => $fields,
'optionsCategory' => $optionsCategory,
'optionsStatus' => $optionsStatus,
'optionsGroup' => $optionsGroup,
'error' => $error]);
}
}
return $rc;
}
private function rules(bool $isCreation=false): array
{
$rc = [
'title' => 'required',
'body' => 'required',
'category_id' => 'required',
'status_id' => 'required',
'group_id' => 'required',
];
return $rc;
}
public function store(Request $request)
{
if ($request->btnSubmit === 'btnStore') {
$incomingFields = $request->validate($this->rules());
$incomingFields['user_id'] = auth()->id();
$incomingFields['title'] = strip_tags($incomingFields['title']);
$incomingFields['body'] = strip_tags($incomingFields['body']);
Note::create($incomingFields);
}
return redirect('/note-index');
}
- Datei resources/views/note/create.blade.php
<form id="note-create" action="/note-create" method="POST">
@csrf
<x-laraknife.create-panel title="{{ __('Creation of a Note') }}" error="{{$error}}">
<x-laraknife.combobox position="first" name="status_id" label="Status" value="{{$fields['status_id']}}" :options="$optionsStatus" width2="4" />
<x-laraknife.combobox position="last" name="group_id" label="Group" value="{{$fields['group_id']}}" :options="$optionsGroup" width2="4" />
<x-laraknife.combobox position="alone" name="category_id" label="Category" value="{{$fields['category_id']}}" :options="$optionsCategory" width2="4" />
<x-laraknife.text position="alone" name="title" label="Title" value="{{$fields['title']}}" />
<x-laraknife.bigtext position="alone" name="body" label="Body" value="{{$fields['body']}}" rows="10" />
</x-laraknife.create-panel>
</form>
Ändern (edit)
- Datei app/Http/Controllers/NoteController.php
public function edit(Note $note)
{
if (array_key_exists('btnSubmit', $_POST) && $_POST['btnSubmit'] === 'btnCancel') {
$rc = redirect('/note-index');
} else {
$optionsCategory = SProperty::optionsByScope('category', $note->category_id, '-');
$optionsStatus = SProperty::optionsByScope('notestatus', $note->status_id, '-');
$optionsGroup = SProperty::optionsByScope('group', $note->group_id, '-');
$rc = view('note.edit', [
'note' => $note,
'optionsCategory' => $optionsCategory,
'optionsStatus' => $optionsStatus,
'optionsGroup' => $optionsGroup,
]);
}
return $rc;
}
- Datei resources/views/note/edit.blade.php
<form id="note-edit" action="/note-update/{{ $note->id }}" method="POST">
@csrf
<x-laraknife.edit-panel title="{{ __('Change of a Note') }}">
<x-laraknife.combobox position="first" name="status_id" label="Status" value="{{$note->status_id}}" :options="$optionsStatus" width2="4" />
<x-laraknife.combobox position="last" name="group_id" label="Group" value="{{$note->group_id}}" :options="$optionsGroup" width2="4" />
<x-laraknife.combobox position="alone" name="category_id" label="Category" value="{{$note->category_id}}" :options="$optionsCategory" width2="4" />
<x-laraknife.text position="alone" name="title" label="Title" value="{{$note->title}}" />
<x-laraknife.bigtext position="alone" name="body" label="Body" value="{{$note->body}}" rows="10" />
</x-laraknife.edit-panel>
</form>
Anzeigen (show/delete)
- Datei app/Http/Controllers/NoteController.php
public function show(Note $note)
{
if (array_key_exists('btnSubmit', $_POST) && $_POST['btnSubmit'] === 'btnCancel') {
$rc = redirect('/note-index');
} else {
$optionsCategory = SProperty::optionsByScope('category', 'category', '');
$optionsGroup = SProperty::optionsByScope('group', 'group', '');
$optionsStatus = SProperty::optionsByScope('notestatus', 'status', '');
$rc = view('note.show', [
'note' => $note,
'optionsCategory' => $optionsCategory,
'optionsGroup' => $optionsGroup,
'optionsStatus' => $optionsStatus,
'mode' => 'delete'
]);
}
return $rc;
}
- Datei resources/views/note/show.blade.php
<form id="note-show" action="/note-show/{{ $note->id }}/{{ $mode }}" method="POST">
@csrf
@if ($mode === 'delete')
@method('DELETE')
@endif
<x-laraknife.show-panel title="{{ __($mode !== 'delete' ? 'A Note' : 'Deletion of a Note') }}"
mode="{{ $mode }}">
<x-laraknife.combobox position="first" name="status_id" label="Status" value="{{ $note->status_id }}"
:options="$optionsStatus" width2="4" attribute="readonly" />
<x-laraknife.combobox position="last" name="group_id" label="Group" value="{{ $note->group_id }}"
:options="$optionsGroup" width2="4" attribute="readonly" />
<x-laraknife.combobox position="first" name="category_id" label="Category" value="{{ $note->category_id }}"
:options="$optionsCategory" width2="4" attribute="readonly" />
<x-laraknife.text position="last" name="id" label="Id" value="{{ $note->id }}" width2="4"
attribute="readonly" />
<x-laraknife.text position="alone" name="title" label="Title" value="{{ $note->title }}"
attribute="readonly" />
<x-laraknife.bigtext position="alone" name="body" label="Body" value="{{ $note->body }}" rows="10"
attribute="readonly" />
</x-laraknife.show-panel>
</form>