<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Rss2Model as MainModel;
use App\Http\Requests\Rss2Request as MainRequest;

class Rss2Controller extends AdminController
{
    public function __construct()
    {
        $this->pathViewController = 'admin.pages.rss2.';
        $this->controllerName     = 'rss2';
        $this->model = new MainModel();
        parent::__construct();
        $this->params["pagination"]["totalItemsPerPage"] = 5;
    }

    public function save(MainRequest $request)
    {
        if ($request->method() == 'POST') {
            $params = $request->all();

            $task   = "add-item";
            $notify = "Thêm phần tử thành công!";

            if ($params['id'] !== null) {
                $task   = "edit-item";
                $notify = "Cập nhật phần tử thành công!";
            }
            $this->model->saveItem($params, ['task' => $task]);
            return redirect()->route($this->controllerName)->with("zvn_notify", $notify);
        }
    }
}
