<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class RssFeedController extends Controller {
  public function feed () {
    $select = ['id', 'user_id', 'title', 'slug', 'publish_date', 'message'];
    $posts = DB::table('blg_content')->select($select)->where('isPost', true)->where('public_status', 0)->orderBy('id', 'desc')->limit(50)->get();

    foreach ($posts as $k => $v) {
      $userd = DB::table('users')->where('id', $v->user_id)->first();
      $userd = DB::table('usr_profile')->where('user_id', $v->user_id)->first();
      $v->user = $userd->display_name;
      unset($posts[$k]->user_id);
    }

    return response()->view('rss.feed', ['posts' => $posts])->header('Content-Type', 'application/xml');
  }
}
