Taskx mittels Laraknife: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Zeile 51: | Zeile 51: | ||
npm run dev | npm run dev | ||
# Abbruch mit Strg-C | # Abbruch mit Strg-C | ||
</syntaxhighlight> | |||
== Einrichten LaraKnife == | |||
<syntaxhighlight lang="bash"> | |||
sed -i \ | sed -i \ | ||
-e '/"laravel.ui"/ s=^= "hamatoma/laraknife": "dev-main",<nl>=' \ | -e '/"laravel.ui"/ s=^= "hamatoma/laraknife": "dev-main",<nl>=' \ | ||
Zeile 56: | Zeile 60: | ||
-e "s/<nl>/\\n/g" composer.json | -e "s/<nl>/\\n/g" composer.json | ||
composer update | composer update | ||
vendor/hamatoma/laraknife/scripts/laraknife-tool.sh build-links | |||
</syntaxhighlight> | |||
= Starten Webserver = | |||
<syntaxhighlight lang="bash"> | |||
php artisan serve | |||
</syntaxhighlight> | |||
* Im Browser: http://localhost:8000 | |||
= Modul Notes erstellen = | |||
== Tabellenbeschreibung erstellen == | |||
* Konvention: Tabelle wird kleingeschrieben, im Plural | |||
<syntaxhighlight lang="bash"> | |||
TABLE=notes | |||
php artisan make:migration create_${TABLE}_table | |||
</syntaxhighlight> | |||
* Es wird die Datei database/migrations/2023_12_29_180821_create_notes_table.php erzeugt | |||
* Diese Datei anpassen: | |||
<pre> | |||
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(); | |||
}); | |||
</pre> | |||
== Modul erzeugen == | |||
<syntaxhighlight lang="bash"> | |||
php artisan migrate | |||
./Lara create:module database/migrations/2023_12_29_180821_create_notes_table.php | |||
</syntaxhighlight> | </syntaxhighlight> | ||
= | == Roles und SProperties füllen == | ||
<syntaxhighlight lang="bash"> | |||
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', '<none>', 10, '-', '2023-12-28'), | |||
(2002, 'category', 'private', 20, 'P', '2023-12-28'), | |||
(2003, 'category', 'work', 30, 'W', '2023-12-28'), | |||
(2501, 'group', '<none>', 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 | |||
</syntaxhighlight> |
Version vom 29. Dezember 2023, 21:21 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
sed -i \
-e '/"laravel.ui"/ s=^= "hamatoma/laraknife": "dev-main",<nl>=' \
-e '/^ *"autoload/ s=^= "repositories": [<nl> {"type": "vcs", "url": "https://github.com/hamatoma/laraknife" }<nl> ],<nl>=' \
-e "s/<nl>/\\n/g" composer.json
composer update
vendor/hamatoma/laraknife/scripts/laraknife-tool.sh build-links
Starten Webserver
php artisan serve
- Im Browser: http://localhost:8000
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
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', '<none>', 10, '-', '2023-12-28'),
(2002, 'category', 'private', 20, 'P', '2023-12-28'),
(2003, 'category', 'work', 30, 'W', '2023-12-28'),
(2501, 'group', '<none>', 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