<?php

namespace Modules\Day\Http\Controllers;

use App\Http\Controllers\BasicController;
use Illuminate\Http\Request;
use Modules\Day\Entities\Model;

class Controller extends BasicController
{
    public function index(Request $request)
    {
        $Models = Model::get();

        return view('day::index', compact('Models'));
    }

    public function create()
    {
        return view('day::create');
    }

    public function store(Request $request)
    {
        $Model = Model::create($request->only(['title_ar', 'title_en', 'status']));
        $Model->save();
        alert()->success(__('trans.addedSuccessfully'));

        return redirect()->route(activeGuard().'.days.index');
    }

    public function show($id)
    {
        $Model = Model::where('id', $id)->firstorfail();

        return view('day::show', compact('Model'));
    }

    public function edit($id)
    {
        $Model = Model::where('id', $id)->firstorfail();

        return view('day::edit', compact('Model'));
    }

    public function update(Request $request, $id)
    {
        $Model = Model::where('id', $id)->firstorfail();
        $Model->update($request->only(['title_ar', 'title_en',  'status']));
        $Model->save();
        alert()->success(__('trans.updatedSuccessfully'));

        return redirect()->route(activeGuard().'.days.index');
    }

    public function destroy($id)
    {
        Model::where('id', $id)->delete();
    }
}
