diff --git a/app/Http/ViewComposers/SocialPostsComposer.php b/app/Http/ViewComposers/SocialPostsComposer.php new file mode 100644 index 0000000..5ed93ee --- /dev/null +++ b/app/Http/ViewComposers/SocialPostsComposer.php @@ -0,0 +1,24 @@ +socialPosts = $socialPosts; + $this->instagramPosts = $instagramPosts; + } + + public function compose(View $view) + { + $view->with('twitterPosts', $this->socialPosts->recent())->with('instagramPosts', $this->instagramPosts->recent()); + } +} \ No newline at end of file diff --git a/app/InstagramPost.php b/app/InstagramPost.php new file mode 100644 index 0000000..b2fa1bc --- /dev/null +++ b/app/InstagramPost.php @@ -0,0 +1,33 @@ +where('platform', 'instagram'); + }); + } + + public function recent($limit=3) { + $posts = $this->orderBy('pubDate','desc')->limit($limit)->get(); + + $posts = $posts->map(function ($item) { + return [ + 'srcLarge' => $item->media, + 'srcSmall' => $item->media, + 'socialUrl' => $item->socialUrl, + ]; + }); + + return $posts; + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 91eb8e0..1f00bc9 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,7 +4,6 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\View; -use App\SocialPost; class AppServiceProvider extends ServiceProvider { @@ -25,28 +24,5 @@ public function register() */ public function boot() { - // - //footer variables - //tweets & facebook posts - $twitterArray = SocialPost::whereIn('platform',['twitter','facebook'])->orderBy('pubDate','desc')->limit(3)->get(); - $twitterArray = $twitterArray->map(function ($item) { - return [ - 'source' => $item->platform, - 'data' => $item->text, - 'url' => $item->socialUrl, - 'time' => $item->pubDate, - ]; - }); - - //instagram - $instagramArray = SocialPost::where('platform','instagram')->orderBy('pubDate','desc')->limit(8)->get(); - $instagramArray = $instagramArray->map(function ($item) { - return [ - 'srcLarge' => $item->media, - 'srcSmall' => $item->media, - ]; - }); - - View::share(['instagramArray' => $instagramArray, 'twitterArray' => $twitterArray]); } } diff --git a/app/Providers/ViewServiceProvider.php b/app/Providers/ViewServiceProvider.php new file mode 100644 index 0000000..4310f3a --- /dev/null +++ b/app/Providers/ViewServiceProvider.php @@ -0,0 +1,31 @@ +orderBy('pubDate','desc')->limit($limit)->get(); + + $posts = $posts->map(function ($item) { + return [ + 'source' => $item->platform, + 'data' => $item->text, + 'url' => $item->socialUrl, + 'time' => $item->pubDate, + ]; + }); + + return $posts; + } } diff --git a/config/app.php b/config/app.php index b68d13b..2123423 100644 --- a/config/app.php +++ b/config/app.php @@ -161,6 +161,7 @@ Illuminate\Translation\TranslationServiceProvider::class, Illuminate\Validation\ValidationServiceProvider::class, Illuminate\View\ViewServiceProvider::class, + App\Providers\ViewServiceProvider::class, /* * Package Service Providers... diff --git a/resources/views/components/footer.blade.php b/resources/views/components/footer.blade.php index 06c3616..e7a0389 100644 --- a/resources/views/components/footer.blade.php +++ b/resources/views/components/footer.blade.php @@ -15,7 +15,7 @@