<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Announce\StoreRequest;
use App\Models\Announce;
use Carbon\Carbon;
use Illuminate\Http\Request;

class AnnounceController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $announces = Announce::paginate(10);
    	return view('Admin.Announce.index' , compact('announces'));
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        return view('Admin.Announce.add');
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(StoreRequest $request)
    {
        $request->merge(['date' => Carbon::now()->format('Y-m-d')]);
    	Announce::create($request->all());
		return redirect()->route('announces.index')->with('success_message', 'Record successfully created');
    }

    /**
     * Display the specified resource.
     */
    public function show(Announce $announce)
    {
        return $announce;
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(Announce $announce)
    {
    	return view('Admin.Announce.update' , compact('announce'));
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(StoreRequest $request, Announce $announce)
    {
        $request->merge(['date' => Carbon::now()->format('Y-m-d')]);
    	$announce->update($request->all());
		return redirect()->route('announces.index')->with('success_message', 'Record successfully updated');
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(Announce $announce)
    {
        $announce->delete();
        return redirect()->route('announces.index')->with('success_message', 'Record successfully deleted');
    }
}
