File size: 16,706 Bytes
89a1081
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php

namespace App\Providers;

use App\Enums\StatusEnum;
use App\Models\Blog;
use App\Models\FrontendSection;
use App\Models\PricingPlan;
use App\Models\Subscription;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use App\Models\User;
use App\Models\SMSlog;
use App\Models\EmailLog;

class FrontendViewServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot(): void
    {
        try {
            //Frontend
            $frontendContents = FrontendSection::latest()->get();

            $userId = null;

            if(Auth::check()){
                $userId = Auth::user()->id;
            }
            
           View::composer(['frontend.sections.topbar'], function ($view) use ($frontendContents) {
                $view->with([
                    'service_menu_content' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_menu\.[^.]+\.fixed_content$/', $item->section_key);
                    })->all(),
                    'service_menu_multi_content' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_menu\.[^.]+\.multiple_static_content$/', $item->section_key);
                    })->all(),
                    'service_menu_element' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_menu\.[^.]+\.element_content$/', $item->section_key);
                    })->all(),
                ]);
            });

            //Service Section Data
            View::composer(['frontend.service.section.breadcrumb_banner', ], function ($view) use ($frontendContents) {
                $view->with([
                    'service_breadcrumb_content' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_breadcrumb\.[^.]+\.fixed_content$/', $item->section_key);
                    })->all(),
                    'service_breadcrumb_multi_content' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_breadcrumb\.[^.]+\.multiple_static_content$/', $item->section_key);
                    })->all(),
                    'service_breadcrumb_element' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_breadcrumb\.[^.]+\.element_content$/', $item->section_key);
                    })->all(),
                ]);
            });

            View::composer(['frontend.service.section.overview', ], function ($view) use ($frontendContents) {

                $view->with([
                    'service_overview_content' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_overview\.[^.]+\.fixed_content$/', $item->section_key);
                    })->all(),
                    'service_overview_multi_content' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_overview\.[^.]+\.multiple_static_content$/', $item->section_key);
                    })->all()
                ]);
            });

            View::composer(['frontend.service.section.feature', ], function ($view) use ($frontendContents) {

                $view->with([
                    'service_feature_content' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_feature\.[^.]+\.fixed_content$/', $item->section_key);
                    })->all(),
                    'service_feature_multi_content' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_feature\.[^.]+\.multiple_static_content$/', $item->section_key);
                    })->all(),
                    'service_feature_element' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_feature\.[^.]+\.element_content$/', $item->section_key);
                    })->all(),
                ]);
            });

            View::composer(['frontend.service.section.details', ], function ($view) use ($frontendContents) {

                $view->with([
                    'service_details_content' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_details\.[^.]+\.fixed_content$/', $item->section_key);
                    })->all(),
                    'service_details_multi_content' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_details\.[^.]+\.multiple_static_content$/', $item->section_key);
                    })->all(),
                    'service_details_element' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_details\.[^.]+\.element_content$/', $item->section_key);
                    })->all(),
                ]);
            });

            View::composer(['frontend.service.section.highlight', ], function ($view) use ($frontendContents) {

                $view->with([
                    'service_highlight_content' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_highlight\.[^.]+\.fixed_content$/', $item->section_key);
                    })->all(),
                    'service_highlight_multi_content' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_highlight\.[^.]+\.multiple_static_content$/', $item->section_key);
                    })->all(),
                    'service_highlight_element' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_highlight\.[^.]+\.element_content$/', $item->section_key);
                    })->all(),
                ]);
            });



            View::composer(['frontend.sections.banner', ], function ($view) use ($frontendContents) {
                $view->with([
                    'users' => User::orderBy('id','DESC')->latest()->get(),
                    'social_icons'=> $frontendContents->where('section_key', FrontendSection::SOCIAL_ICON),
                    'banner_content'=> $frontendContents->where('section_key', FrontendSection::BANNER_CONTENT)->first(),
                    'banner_element'=> $frontendContents->where('section_key', FrontendSection::BANNER_ELEMENT),
                ]);
            });

            View::composer(['frontend.sections.client', ], function ($view) use ($frontendContents) {
                $view->with([
                    'client_content'=> $frontendContents->where('section_key', FrontendSection::CLIENT_CONTENT)->first(),
                    'client_multi_content'=> $frontendContents->where('section_key', FrontendSection::CLIENT_MULTI_CONTENT)->first(),
                ]);
            });

            View::composer(['frontend.sections.feature', ], function ($view) use ($frontendContents) {
                $view->with([
                    'feature_content'=> $frontendContents->where('section_key', FrontendSection::FEATURE_CONTENT)->first(),
                    'feature_multi_content'=> $frontendContents->where('section_key', FrontendSection::FEATURE_MULTI_CONTENT)->first(),
                    'feature_element'=> $frontendContents->where('section_key', FrontendSection::FEATURE_ELEMENT),
                ]);
            });

            View::composer(['frontend.sections.workflow', ], function ($view) use ($frontendContents) {
                $view->with([
                    'workflow_content'=> $frontendContents->where('section_key', FrontendSection::WORKFLOW_CONTENT)->first(),
                    'workflow_multi_content'=> $frontendContents->where('section_key', FrontendSection::WORKFLOW_MULTI_CONTENT)->first(),
                    'workflow_element'=> $frontendContents->where('section_key', FrontendSection::WORKFLOW_ELEMENT),
                ]);
            });

            View::composer(['frontend.sections.feedback', ], function ($view) use ($frontendContents) {
                $view->with([
                    'feedback_content'=> $frontendContents->where('section_key', FrontendSection::FEEDBACK_CONTENT)->first(),
                    'feedback_multi_content'=> $frontendContents->where('section_key', FrontendSection::FEEDBACK_MULTI_CONTENT)->first(),
                    'feedback_element'=> $frontendContents->where('section_key', FrontendSection::FEEDBACK_ELEMENT),
                ]);
            });

            View::composer(['admin.auth.feedback', ], function ($view) use ($frontendContents) {
                $view->with([
                    'feedback_content'=> $frontendContents->where('section_key', FrontendSection::FEEDBACK_CONTENT)->first(),
                    'feedback_multi_content'=> $frontendContents->where('section_key', FrontendSection::FEEDBACK_MULTI_CONTENT)->first(),
                    'feedback_element'=> $frontendContents->where('section_key', FrontendSection::FEEDBACK_ELEMENT),
                ]);
            });

            View::composer(['frontend.sections.advantage', ], function ($view) use ($frontendContents) {
                $view->with([
                    'advantage_content'=> $frontendContents->where('section_key', FrontendSection::ADVANTAGE_CONTENT)->first(),
                    'advantage_multi_content'=> $frontendContents->where('section_key', FrontendSection::ADVANTAGE_MULTI_CONTENT)->first(),
                    'advantage_element'=> $frontendContents->where('section_key', FrontendSection::ADVANTAGE_ELEMENT),
                ]);
            });

            View::composer(['frontend.sections.faq', ], function ($view) use ($frontendContents) {
                $view->with([
                    'faq_content'=> $frontendContents->where('section_key', FrontendSection::FAQ_CONTENT)->first(),
                    'faq_multi_content'=> $frontendContents->where('section_key', FrontendSection::FAQ_MULTI_CONTENT)->first(),
                    'faq_element'=> $frontendContents->where('section_key', FrontendSection::FAQ_ELEMENT),
                ]);
            });

            View::composer(['frontend.sections.plan', ], function ($view) use ($frontendContents) {

                $pricingPlans = PricingPlan::where('status', StatusEnum::TRUE->status())
                                                ->where('amount', '>=', 1)
                                                ->orderBy('amount', 'ASC')
                                                ->get();
                $recommendedStatusRow = $pricingPlans->firstWhere('recommended_status', StatusEnum::TRUE->status());
                if ($recommendedStatusRow) {
                    $pricingPlans = $pricingPlans->filter(function ($item) use ($recommendedStatusRow) {
                        return $item->id !== $recommendedStatusRow->id;
                    })->values();
                }
                if ($recommendedStatusRow) {
                    $pricingPlans->splice(1, 0, [$recommendedStatusRow]);
                }
                $view->with([
                    'plan_content' => $frontendContents->where('section_key', FrontendSection::PLAN_CONTENT)->first(),
                    'plans'        => $pricingPlans,
                ]);
            });

            View::composer(['frontend.sections.gateway', ], function ($view) use ($frontendContents) {
                $view->with([
                    'gateway_content'=> $frontendContents->where('section_key', FrontendSection::GATEWAY_CONTENT)->first(),
                    'gateway_multi_content'=> $frontendContents->where('section_key', FrontendSection::GATEWAY_MULTI_CONTENT)->first(),
                    'gateway_element'=> $frontendContents->where('section_key', FrontendSection::GATEWAY_ELEMENT),
                ]);
            });

            View::composer(['frontend.sections.footer', ], function ($view) use ($frontendContents) {
                $view->with([
                    'footer_content'=> $frontendContents->where('section_key', FrontendSection::FOOTER_CONTENT)->first(),
                    'social_element'=> $frontendContents->where('section_key', FrontendSection::SOCIAL_ICON),
                    'pages'=> $frontendContents->where('section_key', FrontendSection::POLICY_PAGES),
                ]);
            });

            View::composer(['frontend.pricing.section.breadcrumb_banner', ], function ($view) use ($frontendContents) {

                $view->with([
                    'pricing_content' => $frontendContents->where('section_key', FrontendSection::PRICING_BREADCRUMB)->first(),
                ]);
            });

            View::composer(['frontend.about.section.breadcrumb_banner', ], function ($view) use ($frontendContents) {

                $view->with([
                    'about_content' => $frontendContents->where('section_key', FrontendSection::ABOUT_BREADCRUMB)->first(),
                ]);
            });

            View::composer(['frontend.about.section.overview', ], function ($view) use ($frontendContents) {

                $view->with([
                    'about_overview' => $frontendContents->where('section_key', FrontendSection::ABOUT_OVERVIEW)->first(),
                ]);
            });
            
            View::composer(['frontend.about.section.connect', ], function ($view) use ($frontendContents) {

                $view->with([
                    'connect_content' => $frontendContents->where('section_key', FrontendSection::CONNECT_SECTION)->first(),
                    'connect_element' => $frontendContents->where('section_key', FrontendSection::CONNECT_ELEMENT),
                ]);
            });

            View::composer(['frontend.contact.section.breadcrumb_banner', ], function ($view) use ($frontendContents) {

                $view->with([
                    'contact_content' => $frontendContents->where('section_key', FrontendSection::CONTACT_BREADCRUMB)->first(),
                ]);
            });
            View::composer(['frontend.contact.section.get_in_touch', ], function ($view) use ($frontendContents) {

                $view->with([
                    'contact_content' => $frontendContents->where('section_key', FrontendSection::GET_IN_TOUCH)->first(),
                ]);
            });

            View::composer(['frontend.sections.blog', ], function ($view) use ($frontendContents) {

                $view->with([
                    'blog_content' => $frontendContents->where('section_key', FrontendSection::BLOG)->first(),
                    'blogs'        => Blog::where('status', StatusEnum::TRUE->status())->latest()->get()
                ]);
            });
            View::composer(['frontend.blog.section.breadcrumb_banner', ], function ($view) use ($frontendContents) {

                $view->with([
                    'blog_content' => $frontendContents->where('section_key', FrontendSection::BLOG_BREADCRUMB)->first(),
                ]);
            });

            View::composer(['frontend.sections.service', ], function ($view) use ($frontendContents) {

                $view->with([
                    'service_menu_common' => $frontendContents->where('section_key', FrontendSection::SERVICE_MENU)->first(),
                    'service_breadcrumb_content' => $frontendContents->filter(function ($item) {
                        return preg_match('/^service_breadcrumb\.[^.]+\.fixed_content$/', $item->section_key);
                    })->all(),
                ]);
            });

            View::composer(['frontend.policy.section.breadcrumb_banner', ], function ($view) use ($frontendContents) {

                $view->with([
                    'page_content' => $frontendContents->where('section_key', FrontendSection::POLICY_CONTENT)->first(),
                ]);
            });
            View::composer(['frontend.auth.partials.content', ], function ($view) use ($frontendContents) {
                $view->with([
                    'user_auth_content'=> $frontendContents->where('section_key', FrontendSection::USER_AUTH_CONTENT)->first(),
                    'user_auth_multi_content'=> $frontendContents->where('section_key', FrontendSection::USER_AUTH_MULTI_CONTENT)->first(),
                    'user_auth_element'=> $frontendContents->where('section_key', FrontendSection::USER_AUTH_ELEMENT),
                ]);
            });

            
        }catch (\Exception $exception){

        }

    }
}