File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -157,7 +157,6 @@ protected function user(): \Illuminate\Foundation\Auth\User
157157 throw new \RuntimeException ( 'User model must extend Illuminate\Foundation\Auth\User ' );
158158 }
159159
160- $ user ->mergeCasts ( ['cmsperms ' => 'array ' ] );
161160 $ user ->forceFill ( [
162161 'name ' => 'Benchmark User ' ,
163162 'email ' => 'benchmark@example.com ' ,
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ public function boot(): void
1818 $ this ->publishes ( [$ basedir . '/config/cms.php ' => config_path ( 'cms.php ' )], 'cms-core-config ' );
1919
2020 $ this ->rateLimiter ();
21+ $ this ->userCasts ();
2122 $ this ->console ();
2223
2324 // Set null Scout driver as fallback if none configured
@@ -69,6 +70,32 @@ protected function scout() : void
6970 }
7071 }
7172
73+ protected function userCasts () : void
74+ {
75+ $ this ->app ->booted ( function () {
76+ $ userClass = config ( 'auth.providers.users.model ' , 'App \\Models \\User ' );
77+
78+ if ( !$ userClass || !class_exists ( $ userClass ) || !method_exists ( $ userClass , 'mergeCasts ' ) ) {
79+ return ;
80+ }
81+
82+ $ casts = ['cmsperms ' => 'array ' ];
83+
84+ $ userClass ::retrieved ( function ( $ model ) use ( $ casts ) {
85+ $ model ->mergeCasts ( $ casts );
86+ } );
87+
88+ $ userClass ::saving ( function ( $ model ) use ( $ casts ) {
89+ $ model ->mergeCasts ( $ casts );
90+
91+ if ( is_array ( $ model ->getAttributes ()['cmsperms ' ] ?? null ) ) {
92+ $ model ->setAttribute ( 'cmsperms ' , $ model ->getAttributes ()['cmsperms ' ] );
93+ }
94+ } );
95+ } );
96+ }
97+
98+
7299 protected function rateLimiter (): void
73100 {
74101 RateLimiter::for ( 'cms-admin ' , fn ( $ request ) =>
You can’t perform that action at this time.
0 commit comments