Last active
November 23, 2020 17:56
-
-
Save emjayess/70397c1361f28cbf34309ea945da3ffa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
/** | |
* shorthand laravel php syntax tips via) | |
* Laravel Business: https://www.youtube.com/post/UgzGftWbzdljAptGJOR4AaABCQ | |
* via Caleb Porzio: https://laravel-livewire.com/screencasts/s7-simple-table | |
*/ | |
// instead of if/else | |
if ( $status == 'processing' ) { | |
return 'blue'; | |
} | |
else if ( $status == 'success' ) { | |
return 'green'; | |
} | |
else if ( $status == 'failure' ) { | |
return 'red'; | |
} | |
// or switch/case | |
switch ( $status ) { | |
case 'processing': return 'blue'; | |
case 'success': return 'green'; | |
case 'failure': return 'red'; | |
} | |
// use array access | |
return [ | |
'processing' => 'blue', | |
'success' => 'green', | |
'failure' => 'red', | |
][ $status ]; | |
// cleaner | |
$statuses = [ | |
'processing' => 'blue', | |
'success' => 'green', | |
'failure' => 'red', | |
]; | |
return $statuses[ $status ]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment