<?php

namespace App\Http\Controllers\Announcement;//call to announcement controller folder
use App\Http\Controllers\Controller;//call to controller class

use App\Models\Announcement;
use Illuminate\Http\Request;

class DeleteAnnouncementController extends Controller
{
    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $announcement = Announcement::findOrFail($id);
        $deleted = $announcement->delete();

        if($deleted)
        {
            session()->put('success', 'Announcement Successfully Deleted!');
            return redirect()->back();
        }
        //the else part
        session()->put('error', 'There was an error deleting this announcement!');
        return redirect()->back();
    }
}
