Skip to content

Commit

Permalink
391. model should be strict & fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrakovich committed Jun 4, 2024
1 parent b1b0f50 commit 137be67
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/app/Models/Data/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function normalizeForGtm()
$gtmUserData['vid'] = $normalizedData['external_id'][0];
$gtmUserData['uid'] = $normalizedData['external_id'][1] ?? null;
$gtmUserData['user_id'] = $gtmUserData['uid'];
$gtmUserData['user_type'] = Auth::check() ? Auth::user()->usergroup_id : 'guest';
$gtmUserData['user_type'] = Auth::check() ? Auth::user()->group_id : 'guest';

return array_filter($gtmUserData);
}
Expand Down
26 changes: 26 additions & 0 deletions src/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
use App\Services\OrderService;
use FacebookAds\Api;
use Illuminate\Database\Connection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Application;
use Illuminate\Notifications\ChannelManager;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
use Sentry\Severity;
use Spatie\Permission\Models\Role;

use function Sentry\captureMessage;

class AppServiceProvider extends ServiceProvider
{
public $bindings = [
Expand Down Expand Up @@ -63,6 +68,8 @@ public function boot(): void
setlocale(LC_TIME, 'ru_RU.UTF-8');
Carbon::setLocale(config('app.locale'));

$this->modelShouldBeStrict($app->isProduction());

if ($app->isProduction()) {
$app['request']->server->set('HTTPS', 'on');
}
Expand All @@ -73,4 +80,23 @@ public function boot(): void

Gate::policy(Role::class, RolePolicy::class);
}

/**
* Model::shouldBeStrict()
*/
private function modelShouldBeStrict(bool $isProduction): void
{
Model::preventAccessingMissingAttributes();
// Warn us when we try to set an unfillable property.
Model::preventSilentlyDiscardingAttributes();

Model::preventLazyLoading(!$isProduction);
// if ($isProduction) {
// Model::handleLazyLoadingViolationUsing(function ($model, $relation) {
// $class = get_class($model);

// captureMessage("Attempted to lazy load [{$relation}] on model [{$class}].", Severity::warning());
// });
// }
}
}
2 changes: 1 addition & 1 deletion src/app/Providers/GoogleTagManagerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function boot()
$userData->setExternalIds([Device::getId(), Auth::id()]);
GoogleTagManagerFacade::push(array_filter([
'pageType' => $page,
'user_type' => Auth::check() ? Auth::user()->usergroup_id : 'guest',
'user_type' => Auth::check() ? Auth::user()->group_id : 'guest',
'user_id' => Auth::id(),
'user_data' => $userData->normalizeForGtm(),
'site_price' => [
Expand Down

0 comments on commit 137be67

Please sign in to comment.