Last active
January 24, 2019 19:32
-
-
Save robertoandres24/1db4278ae54d6c38132c34634bd2d459 to your computer and use it in GitHub Desktop.
Funciones Helpers
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
public function BannersActive() | |
{ | |
return $this->hasMany('App\Ad') | |
->where('user_id', $this->id) | |
->where('status', 1) | |
->get(); | |
} |
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
// busqueda segun determinado substring dentro de los items de un array | |
public function ifExistsInArray($keyword, $arrayToSearch){ | |
foreach($arrayToSearch as $key => $arrayItem){ | |
if( stristr( $arrayItem, $keyword ) ){ //stristr() insensible a mayusculas y minusculas | |
return ['key'=> $key, 'value' => $arrayItem]; | |
} | |
} | |
} |
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
// hace un str_replace y customize para q acepte 1 var o un array en 3er par | |
public function modifyPath($old,$new,$paths){ | |
if (is_array($paths)) { | |
$arrayNewPaths = []; | |
foreach ($paths as $path) { | |
$customPath = str_replace($old, $new, $path); //reemplazar el substring del path y queda | |
$arrayNewPaths[] = $customPath; | |
} | |
return $arrayNewPaths; | |
} | |
else{ | |
$customPath = str_replace($old, $new, $paths); | |
} | |
return $customPath; | |
} |
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 | |
$permitted_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
function generate_string($input, $strength = 16) { | |
$input_length = strlen($input); | |
$random_string = ''; | |
for($i = 0; $i < $strength; $i++) { | |
$random_character = $input[mt_rand(0, $input_length - 1)]; | |
$random_string .= $random_character; | |
} | |
return $random_string; | |
} | |
// Output: iNCHNGzByPjhApvn7XBD | |
echo generate_string($permitted_chars, 20); |
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
public function randomGenerator($qtd){ | |
//Under the string $Caracteres you write all the characters you want to be used to randomly generate the code. | |
$Caracteres = 'ABCDEFGHIJKLMOPQRSTUVXWYZ0123456789'; | |
$QuantidadeCaracteres = strlen($Caracteres); | |
$QuantidadeCaracteres--; | |
$Hash=NULL; | |
for($x=1;$x<=$qtd;$x++){ | |
$Posicao = rand(0,$QuantidadeCaracteres); | |
$Hash .= substr($Caracteres,$Posicao,1); | |
} | |
return $Hash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment