Skip to content

Instantly share code, notes, and snippets.

@EricMcWinNer
Created July 22, 2021 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricMcWinNer/4fd6193d5edbb2259eca147711b2d136 to your computer and use it in GitHub Desktop.
Save EricMcWinNer/4fd6193d5edbb2259eca147711b2d136 to your computer and use it in GitHub Desktop.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
* The booted method of the model
*
* Define all attributes here like normal code
*
* @param string $value
* @return string
*/
protected static function booted() {
static::retrieved(function($user) {
$user->first_name = ucfirst($user->first_name);
$user->phone_number = $user->country_code . $user->phone;
return $user;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment