Skip to content

Instantly share code, notes, and snippets.

@Maxiviper117
Last active June 12, 2025 09:51
Show Gist options
  • Save Maxiviper117/ec944e3d0525b0452b0c9ddb4a06f12d to your computer and use it in GitHub Desktop.
Save Maxiviper117/ec944e3d0525b0452b0c9ddb4a06f12d to your computer and use it in GitHub Desktop.
VSCode php snippets
{
"PHP Public Function": {
"prefix": "p-func-public",
"body": [
"public function ${1:functionName}(${2:parameters})",
"{",
"\t${3:// function body}",
"}"
],
"description": "Create a public function"
},
"PHP Private Function": {
"prefix": "p-func-private",
"body": [
"private function ${1:functionName}(${2:parameters})",
"{",
"\t${3:// function body}",
"}"
],
"description": "Create a private function"
},
"PHP Protected Function": {
"prefix": "p-func-protected",
"body": [
"protected function ${1:functionName}(${2:parameters})",
"{",
"\t${3:// function body}",
"}"
],
"description": "Create a protected function"
},
"PHP Static Public Function": {
"prefix": "p-func-static-public",
"body": [
"public static function ${1:functionName}(${2:parameters})",
"{",
"\t${3:// function body}",
"}"
],
"description": "Create a static public function"
},
"PHP Static Private Function": {
"prefix": "p-func-static-private",
"body": [
"private static function ${1:functionName}(${2:parameters})",
"{",
"\t${3:// function body}",
"}"
],
"description": "Create a static private function"
},
"PHP Public Variable": {
"prefix": "p-var-public",
"body": [
"public ${1:string} $${2:variableName};"
],
"description": "Create a public variable with type"
},
"PHP Private Variable": {
"prefix": "p-var-private",
"body": [
"private ${1:string} $${2:variableName};"
],
"description": "Create a private variable with type"
},
"PHP Protected Variable": {
"prefix": "p-var-protected",
"body": [
"protected ${1:string} $${2:variableName};"
],
"description": "Create a protected variable with type"
},
"PHP Static Public Variable": {
"prefix": "p-var-static-public",
"body": [
"public static ${1:string} $${2:variableName};"
],
"description": "Create a static public variable with type"
},
"PHP Static Private Variable": {
"prefix": "p-var-static-private",
"body": [
"private static ${1:string} $${2:variableName};"
],
"description": "Create a static private variable with type"
},
"PHP Static Protected Variable": {
"prefix": "p-var-static-protected",
"body": [
"protected static ${1:string} $${2:variableName};"
],
"description": "Create a static protected variable with type"
},
"PHP Class": {
"prefix": "p-class",
"body": [
"<?php",
"",
"class ${1:ClassName}",
"{",
"\t${2:// class body}",
"}"
],
"description": "Create a PHP class"
},
"PHP Namespace Class": {
"prefix": "p-class-namespace",
"body": [
"<?php",
"",
"namespace ${1:App\\\\Models};",
"",
"class ${2:ClassName}",
"{",
"\t${3:// class body}",
"}"
],
"description": "Create a PHP class with namespace"
},
"PHP Constructor": {
"prefix": "p-construct",
"body": [
"public function __construct(${1:parameters})",
"{",
"\t${2:// constructor body}",
"}"
],
"description": "Create a constructor method"
},
"PHP Constructor with Property Promotion": {
"prefix": "p-construct-promotion",
"body": [
"public function __construct(",
"\tpublic ${1:string} $${2:property},",
"\t${3:// additional parameters}",
") {",
"\t${4:// constructor body}",
"}"
],
"description": "Create a constructor with property promotion (PHP 8+)"
},
"PHP Interface": {
"prefix": "p-interface",
"body": [
"<?php",
"",
"interface ${1:InterfaceName}",
"{",
"\tpublic function ${2:methodName}(${3:parameters});",
"}"
],
"description": "Create a PHP interface"
},
"PHP Trait": {
"prefix": "p-trait",
"body": [
"<?php",
"",
"trait ${1:TraitName}",
"{",
"\t${2:// trait body}",
"}"
],
"description": "Create a PHP trait"
},
"PHP Try-Catch": {
"prefix": "p-try",
"body": [
"try {",
"\t${1:// code that may throw exception}",
"} catch (${2:Exception} $${3:e}) {",
"\t${4:// handle exception}",
"}"
],
"description": "Create a try-catch block"
},
"PHP Array": {
"prefix": "p-array",
"body": [
"$${1:arrayName} = [",
"\t${2:'key' => 'value',}",
"];"
],
"description": "Create an array"
},
"Laravel Model": {
"prefix": "l-model",
"body": [
"<?php",
"",
"namespace App\\\\Models;",
"",
"use Illuminate\\\\Database\\\\Eloquent\\\\Model;",
"",
"class ${1:ModelName} extends Model",
"{",
"\tprotected $fillable = [",
"\t\t'${2:field}',",
"\t];",
"",
"\t${3:// model methods}",
"}"
],
"description": "Create a Laravel Eloquent model"
},
"Laravel Controller": {
"prefix": "l-controller",
"body": [
"<?php",
"",
"namespace App\\\\Http\\\\Controllers;",
"",
"use Illuminate\\\\Http\\\\Request;",
"",
"class ${1:ControllerName} extends Controller",
"{",
"\tpublic function ${2:index}()",
"\t{",
"\t\t${3:// controller logic}",
"\t}",
"}"
],
"description": "Create a Laravel controller"
},
"Laravel Migration": {
"prefix": "l-migration",
"body": [
"<?php",
"",
"use Illuminate\\\\Database\\\\Migrations\\\\Migration;",
"use Illuminate\\\\Database\\\\Schema\\\\Blueprint;",
"use Illuminate\\\\Support\\\\Facades\\\\Schema;",
"",
"return new class extends Migration",
"{",
"\tpublic function up(): void",
"\t{",
"\t\tSchema::create('${1:table_name}', function (Blueprint $table) {",
"\t\t\t$table->id();",
"\t\t\t${2:// add columns}",
"\t\t\t$table->timestamps();",
"\t\t});",
"\t}",
"",
"\tpublic function down(): void",
"\t{",
"\t\tSchema::dropIfExists('${1:table_name}');",
"\t}",
"};"
],
"description": "Create a Laravel migration"
},
"Livewire Component": {
"prefix": "l-livewire",
"body": [
"<?php",
"",
"namespace App\\\\Livewire;",
"",
"use Livewire\\\\Component;",
"",
"class ${1:ComponentName} extends Component",
"{",
"\tpublic ${2:string} $${3:property} = '';",
"",
"\tpublic function ${4:action}()",
"\t{",
"\t\t${5:// component logic}",
"\t}",
"",
"\tpublic function render()",
"\t{",
"\t\treturn view('livewire.${6:component-name}');",
"\t}",
"}"
],
"description": "Create a Livewire component"
},
"Laravel Route": {
"prefix": "l-route",
"body": [
"Route::${1:get}('${2:path}', [${3:Controller}::class, '${4:method}'])->name('${5:route.name}');"
],
"description": "Create a Laravel route"
},
"Laravel Validation": {
"prefix": "l-validate",
"body": [
"$validated = $request->validate([",
"\t'${1:field}' => '${2:required|string|max:255}',",
"\t${3:// additional validation rules}",
"]);"
],
"description": "Create Laravel validation"
},
"Laravel DB Query": {
"prefix": "l-db-query",
"body": [
"${1:Model}::where('${2:column}', '${3:value}')",
"\t->${4:get}();"
],
"description": "Create a Laravel database query"
},
"Laravel Relationship - HasMany": {
"prefix": "l-rel-has-many",
"body": [
"public function ${1:relationName}()",
"{",
"\treturn $this->hasMany(${2:RelatedModel}::class);",
"}"
],
"description": "Create a hasMany relationship"
},
"Laravel Relationship - BelongsTo": {
"prefix": "l-rel-belongs-to",
"body": [
"public function ${1:relationName}()",
"{",
"\treturn $this->belongsTo(${2:RelatedModel}::class);",
"}"
],
"description": "Create a belongsTo relationship"
},
"Laravel Middleware": {
"prefix": "l-middleware",
"body": [
"<?php",
"",
"namespace App\\\\Http\\\\Middleware;",
"",
"use Closure;",
"use Illuminate\\\\Http\\\\Request;",
"",
"class ${1:MiddlewareName}",
"{",
"\tpublic function handle(Request $request, Closure $next)",
"\t{",
"\t\t${2:// middleware logic}",
"",
"\t\treturn $next($request);",
"\t}",
"}"
],
"description": "Create a Laravel middleware"
},
"PHP Getter Method": {
"prefix": "p-getter",
"body": [
"public function get${1:PropertyName}(): ${2:string}",
"{",
"\treturn $this->${3:property};",
"}"
],
"description": "Create a getter method"
},
"PHP Setter Method": {
"prefix": "p-setter",
"body": [
"public function set${1:PropertyName}(${2:string} $${3:value}): void",
"{",
"\t$this->${4:property} = $${3:value};",
"}"
],
"description": "Create a setter method"
},
"PHP Constant": {
"prefix": "p-const",
"body": [
"public const ${1:CONSTANT_NAME} = '${2:value}';"
],
"description": "Create a class constant"
},
"PHP Abstract Class": {
"prefix": "p-abstract",
"body": [
"<?php",
"",
"abstract class ${1:AbstractClassName}",
"{",
"\tabstract public function ${2:abstractMethod}(${3:parameters});",
"",
"\t${4:// concrete methods}",
"}"
],
"description": "Create an abstract class"
},
"PHP Enum": {
"prefix": "p-enum",
"body": [
"<?php",
"",
"enum ${1:EnumName}: ${2:string}",
"{",
"\tcase ${3:CASE_NAME} = '${4:value}';",
"\t${5:// additional cases}",
"}"
],
"description": "Create a PHP 8.1+ enum"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment