<?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 UpdateAnnouncementController extends Controller
{
    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $validatedData = $request->validate([
            'content' => 'required',
        ]);
        $updated = Announcement::whereId($id)->update($validatedData);
        if($updated)
        {
            session()->put('success', 'Announcement Successfully Updated!');
            return redirect()->back();
        }
        //the else part
        session()->put('error', 'There was an error updating this announcement!');
        return redirect()->back();
    }
}
