<?php

namespace Modules\DeliveryTime\Http\Controllers;

use App\Functions\Upload;
use App\Http\Controllers\BasicController;
use Illuminate\Http\Request;
use Modules\DeliveryTime\Entities\Model;

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

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

    public function create()
    {
        return view('delivery_time::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().'.delivery_times.index');
    }

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

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

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

        return view('delivery_time::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().'.delivery_times.index');
    }

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