Last change
on this file was 0924b6c, checked in by Özkan İliyaz <iliyaz_96@…>, 4 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[0924b6c] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | namespace App\Providers;
|
---|
| 4 |
|
---|
| 5 | use App\Models\Post;
|
---|
| 6 | use App\Models\Category;
|
---|
| 7 | use Illuminate\Support\Facades\View;
|
---|
| 8 | use Illuminate\Support\ServiceProvider;
|
---|
| 9 |
|
---|
| 10 | class AppServiceProvider extends ServiceProvider
|
---|
| 11 | {
|
---|
| 12 | /**
|
---|
| 13 | * Register any application services.
|
---|
| 14 | *
|
---|
| 15 | * @return void
|
---|
| 16 | */
|
---|
| 17 | public function register()
|
---|
| 18 | {
|
---|
| 19 | //
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | /**
|
---|
| 23 | * Bootstrap any application services.
|
---|
| 24 | *
|
---|
| 25 | * @return void
|
---|
| 26 | */
|
---|
| 27 | public function boot()
|
---|
| 28 | {
|
---|
| 29 | View::composer('*', function ($view) {
|
---|
| 30 |
|
---|
| 31 | $blogCategories = collect();
|
---|
| 32 | $allCategories = Category::all();
|
---|
| 33 |
|
---|
| 34 | foreach($allCategories as $c) {
|
---|
| 35 | if(Post::where([
|
---|
| 36 | "category_id" => $c->id,
|
---|
| 37 | "is_confirmed" => true,
|
---|
| 38 | "is_active" => true
|
---|
| 39 | ])->count() > 0) {
|
---|
| 40 | $blogCategories->push($c);
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | $latestPostsFooter = Post::orderBy("created_at", "desc")->take(10)->get();
|
---|
| 45 |
|
---|
| 46 | $view->with("blogCategories", $blogCategories);
|
---|
| 47 | $view->with("latestPostsFooter", $latestPostsFooter);
|
---|
| 48 | });
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.