Change return type from mixed to ?Model on getFirts and getById methods.

This commit is contained in:
kj 2023-03-25 18:28:21 -04:00
parent 11141a0eee
commit 4d052efba6
1 changed files with 5 additions and 4 deletions

View File

@ -702,9 +702,10 @@ class Model {
* Si no encuentra una instancia, devuelve nulo. * Si no encuentra una instancia, devuelve nulo.
* *
* @param mixed $id * @param mixed $id
* @return mixed *
* @return Model|null
*/ */
public static function getById($id) { public static function getById($id): ?Model {
return static::where(static::$primaryKey, $id)->getFirst(); return static::where(static::$primaryKey, $id)->getFirst();
} }
@ -774,10 +775,10 @@ class Model {
* @param bool $resetQuery * @param bool $resetQuery
* (opcional) Indica si el query debe reiniciarse o no (por defecto es true). * (opcional) Indica si el query debe reiniciarse o no (por defecto es true).
* *
* @return mixed * @return Model|null
* Puede retornar un objeto Model o null. * Puede retornar un objeto Model o null.
*/ */
public static function getFirst(bool $resetQuery = true) { // Devuelve null si no encuentra nada. public static function getFirst(bool $resetQuery = true): ?Model { // Devuelve null si no encuentra nada.
static::limit(1); static::limit(1);
$instances = static::get($resetQuery); $instances = static::get($resetQuery);
return empty($instances) ? null : $instances[0]; return empty($instances) ? null : $instances[0];