Last active
December 13, 2019 19:06
PHP/Laravel snippets to VSCode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Create public function": { | |
"prefix": "pubf", | |
"body": [ | |
"public function $1($2)", | |
"{", | |
"\t$3", | |
"}" | |
], | |
"description": "Public function block" | |
}, | |
"Create private function": { | |
"prefix": "prif", | |
"body": [ | |
"private function $1($2)", | |
"{", | |
"\t$3", | |
"}" | |
], | |
"description": "Private function block" | |
}, | |
"Create protected function": { | |
"prefix": "prof", | |
"body": [ | |
"protected function $1($2)", | |
"{", | |
"\t$3", | |
"}" | |
], | |
"description": "Protected function block" | |
}, | |
"Create post method": { | |
"prefix": "lpost", | |
"body": [ | |
"$$validation = Validator::make($$request->all(), $1);", | |
"\nif ($$validation->fails()) {", | |
"\treturn response()->json($$validation->errors(), 422);", | |
"}", | |
"try {", | |
"\t$$user = auth()->user();", | |
"\n\t$2\n", | |
"\treturn response()->json(['created' => true]);", | |
"} catch (\\ModelNotFoundException $$e) {", | |
"\treturn response()->json(['created' => false, 'error' => $$e->getMessage()], 404);", | |
"} catch (\\Exception $$e) {", | |
"\treturn response()->json(['created' => false, 'error' => $$e->getMessage()], 500);", | |
"}" | |
], | |
"description": "Create a Laravel POST method" | |
}, | |
"Create try catch": { | |
"prefix": "ltry", | |
"body": [ | |
"try {", | |
"\t$2\n", | |
"\treturn response()->json(['$1' => true]);", | |
"} catch (ModelNotFoundException $$e) {", | |
"\treturn response()->json(['$1' => false, 'error' => 'Recurso não encontrado'], 404);", | |
"} catch (\\Exception $$e) {", | |
"\tapp('sentry')->captureException($$e);", | |
"\treturn response()->json(['$1' => false, 'error' => 'Algo inesperado aconteceu'], 500);", | |
"}" | |
], | |
"description": "Laravel try catch block" | |
}, | |
"Create json response": { | |
"prefix": "lrj", | |
"body": "return response()->json([], $1);" | |
}, | |
"Create getter method": { | |
"prefix": "pfget", | |
"body": [ | |
"public function get$1($2)", | |
"{", | |
"\treturn $$this->$3;", | |
"}" | |
], | |
"description": "Create getter" | |
}, | |
"Create setter method": { | |
"prefix": "pfset", | |
"body": [ | |
"public function set$1($2)", | |
"{", | |
"\t$$this->$3 = $2;", | |
"}" | |
], | |
"description": "Create setter" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment