<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\{ShippingAddress, Contact, ProductCategory, About};
use Session;

class AddressController extends Controller
{
    public function index(Request $request){
        $q_name = $request->q_name;
        $q_category_id = $request->q_category_id;
        $category_name = "";
        $shipping_address = ShippingAddress::where('user_id', auth()->user()->id)->get();
        $about = About::first();
        $product_category = ProductCategory::limit(5)->get();
        $contact = Contact::first();

        return view('apps.web.shipping_address')->with('shipping_address', $shipping_address)
                                    ->with('category_name' ,$category_name)
                                    ->with('q_name', $q_name)
                                    ->with('about', $about)
                                    ->with('q_category_id', $q_category_id)
                                    ->with('product_category', $product_category)
                                    ->with('contact', $contact);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function insert(Request $request)
    {
        $data = $request->all();

        $data['user_id'] = auth()->user()->id;
        $shipping_address = ShippingAddress::create($data);

        Session::flash('flash_message', 'Data telah ditambah');
        return redirect()->back();
    }


}
