public static function boot() { parent::boot(); static::creating(function ($obj) { $obj->status = 'active'; }); }
public static function boot() { parent::boot(); static::creating(function ($obj) { $fullAddr = implode(', ', array_map(function ($f) use($obj) { return $obj->{$f}; }, ['address', 'city', 'state', 'postal_code', 'country'])); try { $geocoded = App::make('geocoder')->geocode($fullAddr); $obj->latitude = $geocoded->getLatitude(); $obj->longitude = $geocoded->getLongitude(); } catch (\Exception $e) { // swallow error and leave lat/lng blank } }); // static::created(function($obj) { // $obj->campaigns()->sync([Campaign::current()->id]); // foreach( CallToAction::all() as $cta ) { // $data = [ // 'organization_id' => $obj->id, // 'call_to_action_id' => $cta->id, // 'participating' => true, // ]; // OrganizationCallToAction::create($data); // } // }); }
public static function boot() { parent::boot(); static::saving(function ($obj) { if (isset($obj->password)) { if ('' != $obj->password && null != $obj->password) { $obj->password_hash = Hash::make($obj->password); } } unset($obj->password); unset($obj->password_confirmation); }); }