Render two tables in one loop

Posted 3 months ago by germanraffo

Hi friends! Im developing my first Laravel app. Im making a simple CMS with two type of content: galleries and videos.

Im trying to make a home page that render all the galleries and videos in a grid, ordered by publish date. Galleries and Videos don't have relation between them, but i want to render them in the same loop.

public function show()
      $videos = Video::published()->get();
      $galleries = Gallery::published()->get();
      return view('welcome', compact('videos', 'galleries'));

This is my [email protected] ; the published() function is a scope that fetch all content by date.

I know how to send videos and galleries data to the view, but i dont know how to render them in the same loop and make something like: "if is gallery render like this ; and if is video render like that", all sorted by publish date.

Thanks a lot! And excuse me for my bad english, im from Argentina. Best regards!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.