Laravel

Der Schöne

Kursdateien

  • de.zip (3,24 KiB / 23.07.2023 23:26:06)

Icon Erweiterungen Liste der Erweiterungen

HTML

  • HTML Extension Pack von JAderBass Extension Pack für die JAderBass web'n'more HTML/CSS-Kurse
    In diesem Extension Pack sind enthalten:
    • Auto Close Tag von Jun Han Bewirkt, dass bei der Eingabe eines Tags das dazugehörige schließende Tag gleich mit angegeben wird
    • Autoprefixer von mrmlnc Fügt automatisch die eingestellten Vendor-Prefixe für CSS-Regeln hinzu
    • Better Comments von Aaron Bond Macht verschiedenfarbige Kommentare möglich
    • HTML CSS Support von ecmel Bewirkt HTML-class und -id Attribut-Vervollständigung
    • HTML End Tag Labels von Ante Primorac Blendet an End-Tags die ID- und Klassenbezeichnungen ein, um den Code übersichtlicher zu gestalten

PHP

Laravel

  • Laravel Blade Snippets von Winnie Lin Synthax Highlighting und Snippets für Blade-Dateien
    (nur für Arbeit mit Laravel)

Hinweis

Laravel ist ein weit verbreitetes PHP-Framework. Für die Entwicklung bringt Laravel einen eigenen Webserver mit.

Da wir allerdings mit Datenbanken arbeiten und geringe administrative Aufgaben erledigen müssen, sollte ein Datenbank-Server installiert sein.

Bisher habe ich, um lokal wie mit einem "echten" Webserver arbeiten zu können XAMPP benutzt. Ein Packet, welches einen komplett aufgesetzten Apache-Webserver mit PHP- und MariaDB-Unterstützung etc. beinhaltet. Leider ist es momentan so, dass die letzte PHP-Version, welche XAMPP unterstützt, nicht mehr aktiv supportet wird.

Aus diesem Grund nutze ich jetzt Laragon. Dieses Paket beinhaltet ebenfalls alle wichtigen Tools (u.a. PHP und einen MariaDB-Server) um lokal einen funktionierenden Webserver (Apache) für die Arbeit als Webentwickler durchführen zu können. Das Paket kann unter https://laragon.org/download/ heruntergeladen und installiert werden.

PHP Executable Path einstellen

  1. über STRG + , die Settings öffnen
  2. oben rechts auf das kleine Datei-Icon klicken settings icon
  3. der Eintrag "php.validate.executablePath": "" wird ans Ende der Datei settings.json geschrieben. Diesen Eintrag mit dem Pfad der PHP-Erweiterung ergänzen.
    solltest Du noch XAMPP mit der Standard-Installation nutzen, sieht der komplette Eintrag folgendermaßen aus:
                        
    "php.validate.executablePath": "c:/xampp/php/php.exe"
                        
                      
    Wenn Du Laragon mit der Standard-Installation nutzt, nimmst Du folgenden Eintrag:
                        
    "php.validate.executablePath": "c:/laragon/bin/php.exe"
                        
                      

Eigene Code-Snippets nutzen

Ich habe für meine Kurse eigene Code-Snippet-Dateien erstellt, die das Coding erheblich erleichtern. Mit den folgenden Schritten kannst du diese Snippets selbst nutzen:

  • Snippets-Verzeichnis öffnen:
    • Windows:
      %APPDATA%\Code\User\snippets
    • Mac:
      ~/Library/Application Support/Code/User/snippets/
    • Linux:
      $HOME/.config/Code/User/snippets/
  • Variante 1 (empfohlen):
  • Variante 2:
    • Die Datei(en) in einem Editor öffnen, bzw.
    • eine Text-Datei anlegen und unter dem Namen jdb-html.code-snippets bzw. jdb-php.code-snippets bzw. jdb-laravel.code-snippets im oben genannten Verzeichnis speichern und
    • unten stehenden Code in die neue(n) Datei(en) kopieren, bzw. die bestehende(n) Datei(en) nach dem unten stehenden Muster ändern oder:
  • Variante 3:
    • Im VSCode unter Datei > Einstellungen > Benutzercodeschnipsel konfigurieren (Windows) bzw. Code > Einstellungen > Benutzercodeschnipsel konfigurieren (Mac) eine "Neue globale Codeschnipseldatei..." erstellen und diese z.B. jdb-html.code-snippets bzw. jdb-php.code-snippets bzw. jdb-laravel.code-snippets benennen.
    • Den unten stehenden Code in diese Datei kopieren und speichern.

Snippets für Laravel

                  
{
	// HTML
	// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
	// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is 
	// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: 
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. 
	// Placeholders with the same ids are connected.
	// Example:
	// "Print to console": {
	// 	"scope": "javascript,typescript",
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
	"Kommentar Titel HTML": {
		"scope": "html",
		"prefix": "komtitel",
		"body": [
			"<!-- ${1:Titel}",
			"============================================================================================= -->"
		],
		"description": "Ausgabe eines Kommentar-Titels in HTML-Dateien"
	},
	"Kommentar Titel CSS/SCSS": {
		"scope": "css,scss",
		"prefix": "komtitel",
		"body": "/* === ${1:Titel} === */",
		"description": "Ausgabe eines Kommentar-Titels in CSS-Dateien"
	},
	"Bootstrap 5 Grundgerüst nur CSS": {
		"scope": "html,php,blade",
		"prefix": "bs5",
		"description": "Bootstrap Grundgerüst nur CSS",
		"body": [
			"<!DOCTYPE html>",
			"<html lang=\"de\">",
			"<head>",
			"\t<meta charset=\"UTF-8\">",
			"\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">",
			"\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",
			"\t<title>${1:Document}</title>",
			"\t<!-- CSS only -->",
			"\t<!-- Bootstrap-CSS -->",
			"\t<link rel=\"stylesheet\" href=\"css/bootstrap.min.css\">",
			"\t<!-- Custom-CSS -->",
			"\t<link rel=\"stylesheet\" href=\"$2\">",
			"</head>",
			"<body>",
			"\t$3",
			"</body>",
			"</html>"
		]
	},
	"Bootstrap 5 Grundgerüst mit JS": {
		"scope": "html,php,blade",
		"prefix": "bs5js",
		"description": "Bootstrap Grundgerüst - komplett mit JavaScript",
		"body": [
			"<!DOCTYPE html>",
			"<html lang=\"de\">",
			"<head>",
			"\t<meta charset=\"UTF-8\">",
			"\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">",
			"\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">",
			"\t<title>${1:Document}</title>",
			"\t<!-- CSS only -->",
			"\t<!-- Bootstrap-CSS -->",
			"\t<link rel=\"stylesheet\" href=\"css/bootstrap.min.css\">",
			"\t<!-- Custom-CSS -->",
			"\t<link rel=\"stylesheet\" href=\"$2\">",
			"</head>",
			"<body>",
			"\t$3",
			"<!-- Bootstrap JavaScript -->",
			"<script src=\"js/bootstrap.bundle.min.js\"></script>",
			"</body>",
			"</html>"
		]
	},
	"Bootstrap JS": {
		"scope": "html,php,blade",
		"prefix": "bs5jsonly",
		"description": "Bootstrap JavaScript",
		"body": [
			"<!-- Bootstrap JavaScript -->",
			"<script src=\"js/bootstrap.bundle.min.js\"></script>"
		]
	}
}                  
                

                  
{
	// PHP
	// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 
	// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is 
	// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: 
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. 
	// Placeholders with the same ids are connected.
	// Example:
	// "Print to console": {
	// 	"scope": "javascript,typescript",
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
	"Schreibe Header": {
		"scope": "php",
		"prefix": "phead",
		"body": [
			"require_once( '../includes/functions.inc.php' );",
			"/*",
			"* get_header(",
			"*\tstring \\$title,",
			"*\tstring/array \\$css=NULL,",
			"*\tbool \\$bootstrap=false,",
			"*\tstring \\$header=NULL,",
			"*\tarray \\$nav=NULL,",
			"*\tbool \\$fluid=false",
			"* )",
			"*/",
			"\\$args = array(",
			"\t$1",
			");",
			"get_header( ...\\$args );",
			"?>"
		],
		"description": "Fügt das Script für die Einbindung des HTML-Headers ein"
	},
	"Schreibe Footer": {
		"scope": "php",
		"prefix": "pfoot",
		"body": "<?php get_footer(); ?>",
		"description": "Fügt das Script für die Einbindung des HTML-Footers ein"
	},
	"PHP-Bereich": {
		"scope": "html",
		"prefix": "php",
		"body": "<?php $0 ?>",
		"description": "Fügt einen PHP-Bereich ein."
	},
	"PHP-Ausgabe": {
		"scope": "html",
		"prefix": "pecho",
		"body": "<?= $0 ?>",
		"description": "Fügt eine PHP-Ausgabe ein."
	},
	"PHP-Bereich Umbruch": {
		"scope": "html",
		"prefix": "php+",
		"body": [
			"<?php",
			"\t",
			"\t$0",
			"\t",
			"?>"
		],
		"description": "Fügt einen PHP-Bereich mit Zeilenumbrüchen ein."
	},
	"Formular Eigenaufruf": {
		"scope": "php,html",
		"prefix": "formself",
		"body": [
			"<form action=\"<?= \\$_SERVER['SCRIPT_NAME']; ?>\" method=\"post\">",
			"\t$0",
			"</form>"
		],
		"description": "Fügt einen Formular-Bereich mit Selbstaufruf ein."
	},
	"Grundgerüst für PHP": {
		"scope": "php,html",
		"prefix": "pfull",
		"body": [
			"<?php",
			"require_once( '../includes/functions.inc.php' );",
			"/* get_header(",
			"*\tstring \\$title,",
			"*\tstring/array \\$css=NULL,",
			"*\tbool \\$bootstrap=false,",
			"*\tstring \\$header=NULL,",
			"*\tarray \\$nav=NULL,",
			"*\tbool \\$fluid=false",
			"* )",
			"*/",
			"\\$args = array(",
			"\t$1",
			");",
			"get_header( ...\\$args );",
			"?>",
			"\t$2",
			"<?php get_footer(); ?>"
		],
		"description": "Fügt das Grundgerüst für den PHP-Kurs ein."
	},
	"Grundgerüst PHP mit DB": {
		"scope": "php,html",
		"prefix": "pfulldb",
		"body": [
			"<?php",
			"require_once( '../includes/functions.inc.php' );",
			"\\$database = $1;",
			"/* get_header(",
			"*\tstring \\$title,",
			"*\tstring/array \\$css=NULL,",
			"*\tbool \\$bootstrap=false,",
			"*\tstring \\$header=NULL,",
			"*\tarray \\$nav=NULL,",
			"*\tbool \\$fluid=false",
			"* )",
			"*/",
			"\\$args = array(",
			"\t$2",
			");",
			"get_header( ...\\$args );",
			"require_once( '../includes/pdo-connect.inc.php' );",
			"?>",
			"\t$3",
			"<?php get_footer(); ?>"
		],
		"description": "Fügt das Grundgerüst für den PHP-Kurs inklusive Datenbankzugriff ein."
	},
	"var_dump()": {
		"scope": "php",
		"prefix": "vd",
		"body":  "echo '<pre>', var_dump( $1 ), '</pre>';",
		"description": "Gibt ein pre-formatiertes var_dump() aus."
	},
	"var_dump()+": {
		"scope": "php",
		"prefix": "vd+",
		"body":  [
			"echo '<pre>';",
			"var_dump( $1 )",
			"echo '</pre>';"
		],
		"description": "Gibt ein pre-formatiertes var_dump() mit Zeilenumbrüchen aus."
	},
	"print_r()": {
		"scope": "php",
		"prefix": "pr",
		"body":  "echo '<pre>', print_r( $1 ), '</pre>';",
		"description": "Gibt ein pre-formatiertes print_r() aus."
	},
	"print_r()+": {
		"scope": "php",
		"prefix": "pr+",
		"body":  [
			"echo '<pre>'", 
			"print_r( $1 )",
			"echo '</pre>';"
		],
		"description": "Gibt ein pre-formatiertes print_r() mit Zeilenumbrüchen aus."
	},
	"Absatzausgabe PHP": {
		"scope": "php",
		"prefix": "ep",
		"body":  "echo '<p>' . $1 . '</p>';",
		"description": "Gibt per echo je ein Absatz-Anfangs und Ende-Tag aus und setzt den Zeiger in die Zeile dazwischen."
	},
	"Absatzausgabe PHP mit Umbruch": {
		"scope": "php",
		"prefix": "ep+",
		"body":  [
			"echo '<p>';", 
			"$1",
			"echo '</p>';"
		],
		"description": "Gibt per echo je ein Absatz-Anfangs und Ende-Tag aus und setzt den Zeiger in die Zeile dazwischen."
	},
	"Kommentar Titel PHP": {
		"scope": "php",
		"prefix": "komtitel",
		"body": [
			"/* === ${1:Titel}",
			"============================================================================================= */"
		],
		"description": "Ausgabe eines Kommentar-Titels in PHP-Dateien"
	},
	"ausführlicher Kommentar": {
		"scope": "php",
		"prefix": "komfull",
		"body": [
			"/**",
			" * ${1:Summary}",
			" *",
			" * ${2:Description}",
			" *",
			" * @author ${3}",
			" *",
			" * @since ${4:x.x.x}",
			" *",
			" * @see ${5:function/method/class} relied on",
			" * @link ${6:url}",
			" * @global ${7:type} ${8:varname} ${9:Description}.",
			" * @param ${10:type} ${11:var} ${12:Optional. / Description. / Default.}",
			" * @return ${13:type} ${14:Description}.",
			" */"
		],
		"description": "Ausgabe eines ausführlichen Kommentar-Textes zur Beschreibung von Funktionen / Methoden / Klassen in PHP-Dateien"
	},
	"PHP SQL-Abfrage": {
		"scope": "php",
		"prefix": "sqlquery",
		"body": [
			"\\$sql = $1;",
			"",
			"\\$result = mysqli_query( \\$db, \\$sql );",
			"",
			"if( false === \\$result ) {",
			"\t$2",
			"} else {",
			"\techo get_db_error( \\$db, \\$sql );",
			"}"
		],
		"description": "MySQLi Abfrage + Auswertung"
	},
	"PHP PDO-SELECT-Abfrage": {
		"scope": "php",
		"prefix": "pdoselect",
		"body": [
			"\\$sql = '$1';",
			"",
			"try {",
			"\tif (\\$stmt = \\$pdo->query(\\$sql)) {",
			"\t\tif( \\$stmt->rowCount() === 0 ) {",
			"\t\t\techo '<p>Keine Datensätze gefunden.</p>';",
			"\t\t} else {",
			"\t\t\twhile (\\$row = \\$stmt->fetch(PDO::FETCH_OBJ)) {",
			"\t\t\t\t$2",
			"\t\t\t}",
			"\t\t}",
			"\t}",
			"} catch (PDOException \\$e) {",
			"\techo get_db_error(\\$pdo, \\$sql, \\$e);",
			"}",
			"\\$stmt = NULL;",
			"\\$pdo = NULL;"
		],
		"description": "PDO SELECT"
	},
	"PHP PDO-SELECT-Prepared": {
		"scope": "php",
		"prefix": "ppselect",
		"body": [
			"\\$sql = 'SELECT $1 FROM $2';",
			"",
			"try {",
			"\tif (\\$stmt = \\$pdo->prepare(\\$sql)) {",
			"\t\t\\$stmt->bindParam( $3, $4);",
			"\t\t\\$stmt->execute();",
			"\t\tif( \\$stmt->rowCount() === 0 ) {",
			"\t\t\techo '<p>Keine Datensätze gefunden.</p>';",
			"\t\t} else {",
			"\t\t\twhile (\\$row = \\$stmt->fetch(PDO::FETCH_ASSOC)) {",
			"\t\t\t\t$5",
			"\t\t\t}",
			"\t\t}",
			"\t}",
			"} catch (PDOException \\$e) {",
			"\techo get_db_error(\\$pdo, \\$sql, \\$e);",
			"}",
			"\\$stmt = NULL;",
			"\\$pdo = NULL;"
		],
		"description": "PDO SELECT mit Prepared Statements"
	},
	"PHP PDO-INSERT-Prepared": {
		"scope": "php",
		"prefix": "ppinsert",
		"body": [
			"if(!empty(\\$_POST)) {",
			"\t\\$sql = 'INSERT INTO $1",
			"\t(",
			"\t\t$2",
			"\t)",
			"\tVALUES",
			"\t(",
			"\t\t$3",
			"\t)';",
			"\t",
			"\ttry {",
			"\t\tif (\\$stmt = \\$pdo->prepare(\\$sql)) {",
			"\t\t\t\\$stmt->bindParam( $4, $5);",
			"",
			"\t\t\tif( \\$stmt->execute() ) {",
			"\t\t\t\techo '<p>Der Datensatz wurde angelegt</p>';",
			"\t\t\t}",
			"\t\t}",
			"\t} catch (PDOException \\$e) {",
			"\t\techo get_db_error(\\$pdo, \\$sql, \\$e);",
			"\t}",
			"}",
			"\t\\$stmt = NULL;",
			"\t\\$pdo = NULL;"
		],
		"description": "PDO INSERT mit Prepared Statements"
	},
	"PHP PDO-UPDATE-Prepared": {
		"scope": "php",
		"prefix": "ppupdate",
		"body": [
			"if(!empty(\\$_POST)) {",
			"\t\\$sql = 'UPDATE $1",
			"\tSET $2",
			"\tWHERE $3';",
			"\t",
			"\ttry {",
			"\t\tif (\\$stmt = \\$pdo->prepare(\\$sql)) {",
			"\t\t\t\\$stmt->bindParam( $4, $5);",
			"",
			"\t\t\tif( \\$stmt->execute() ) {",
			"\t\t\t\techo '<p>Es wurden ' . \\$stmt->rowCount() . ' Datensätze geändert.</p>';",
			"\t\t\t}",
			"\t\t}",
			"\t} catch (PDOException \\$e) {",
			"\t\techo get_db_error(\\$pdo, \\$sql, \\$e);",
			"\t}",
			"}",
			"\t\\$stmt = NULL;",
			"\t\\$pdo = NULL;"
		],
		"description": "PDO UPDATE mit Prepared Statements"
	},
	"PHP PDO-DELETE-Prepared": {
		"scope": "php",
		"prefix": "ppdel",
		"body": [
			"if(!empty(\\$_POST)) {",
			"\t\\$sql = 'DELETE $1 FROM $2",
			"\tWHERE $3';",
			"\t",
			"\ttry {",
			"\t\tif (\\$stmt = \\$pdo->prepare(\\$sql)) {",
			"\t\t\t\\$stmt->bindParam( $4, $5);",
			"",
			"\t\t\tif( \\$stmt->execute() ) {",
			"\t\t\t\techo '<p>Es wurden ' . \\$stmt->rowCount() . ' Datensätze gelöscht.</p>';",
			"\t\t\t}",
			"\t\t}",
			"\t} catch (PDOException \\$e) {",
			"\t\techo get_db_error(\\$pdo, \\$sql, \\$e);",
			"\t}",
			"}",
			"\t\\$stmt = NULL;",
			"\t\\$pdo = NULL;"
		],
		"description": "PDO DELETE mit Prepared Statements"
	},
	"PHP PDO-Exception handling": {
		"scope": "php",
		"prefix": "pdoerr",
		"body": "echo get_db_error(\\$pdo, \\$sql, \\$e);",
		"description": "PDO Ausnahmebehandlung formatiert ausgeben"
	}
}                  
                

                  
{
	"Laravel Route Get Function": {
		"scope": "php",
		"prefix": "rgf",
		"description": "Erzeugt ein Standard Route::get('', function)",
		"body": ["Route::get( '$1', function() {", "\treturn $2;", "});"]
	},
	"Laravel Route Get Controller": {
		"scope": "php",
		"prefix": "rgc",
		"description": "Erzeugt ein Standard Route::get('', [Controller]])",
		"body": "Route::get( '${1:page}', [${2:Name}Controller::class, '${3:function}'] );"
	}
}                  
                

Anzeige der Uhrzeit in Sprache.