mardi 1 mai 2018

Merging models and ordering by timestamps created_at

I am making an activity page, which will show the activity of a user and i'm wondering the best way to approach this issue of showing the different activity and ordering the activity on the created_at timestamps of all the tables merged.

at the moment i have

Controller

    public function getActivity()
      {
        $blogs = Blogs::where('blogs.user_id', '=', Auth::User()->id)->orderBy('created_at', 'DESC')
        $comments = Comments::where('comments.user_id', '=', Auth::User()->id)- >orderBy('created_at', 'DESC')
        $forumposts = Forumpost::where('forumposts.user_id', '=', Auth::User()->id)->orderBy('created_at', 'DESC')

        return view('myactivity')->withBlogs($blogs)->withComments($comments)->withForumposts($forumposts);

      }

View:

@foreach($blogs as $blog)
    <p>You posted  at </p>

@endforeach 
@foreach($comments as $comment)
    <p>You posted  at </p>

@endforeach 
@foreach($forumposts as $forumpost)
    <p>You posted  at </p>

@endforeach 

The issue with the above code is that it is not merged on one created_at, it is essentially three different created_at lists, how do i merge them into one?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2HLeEWL
via IFTTT

Aucun commentaire:

Enregistrer un commentaire