<?php

namespace App\Http\Controllers;

use App\AddressType;
use Illuminate\Http\Request;

class AddressTypeController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $AddressTypes = AddressType::all();
        return view('AddressType.index',compact('AddressTypes'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('AddressType.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $request-> validate([
            'title'=>'required|max:255',
            'narration'=>'max:255',
        ]);
         AddressType::create($request->all());
        //dd($request);
        
        return redirect(route('AddressType.index'))->with('Message','Saved Successfully');
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\AddressType  $addressType
     * @return \Illuminate\Http\Response
     */
    public function show(AddressType $addressType)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\AddressType  $addressType
     * @return \Illuminate\Http\Response
     */
    public function edit(AddressType $AddressType)
    {
        return view('AddressType.edit', compact('AddressType'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\AddressType  $addressType
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, AddressType $AddressType)
    {
        $request-> validate([
            'title'=>'required|max:255',
            'narration'=>'max:255',        
            
        ]);

        $AddressType->update([
            'title'=>$request->title,
            'narration'=>$request->narration,
        ]);
        
           
        return redirect(route('AddressType.index'))->with('Message','Updated Successfully');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\AddressType  $addressType
     * @return \Illuminate\Http\Response
     */
    public function destroy(AddressType $AddressType)
    {
        $AddressType->delete();
        return redirect(route('AddressType.index'))->with('Message','Deleted Successfully');
    }
}
