<?php

namespace App\Http\Controllers\Portal;

use App\Http\Controllers\Controller;
use App\Models\Forum;
use App\Models\Commune;
use App\Models\Participation;
use Illuminate\Http\Request;

class PublicationsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index($type=null, $id=null)
    {   
        $forums = Forum::orderBy('annee', 'desc')->get();
        $communes = Commune::orderBy('name')->get();

        if ($type and $id) {
            $participations = Participation::where([
                [$type.'_id', $id]
            ])->get();
        } else {
            $participations = Participation::all();
        }
        
        return view('portal.publications.index', [
            'participations' => $participations,
            'forums' => $forums,
            'communes' => $communes,
            'type' => $type,
            'id' => $id,
        ]);
    }
}
