Home > Enterprise >  error shows up when i add Auth::user()->id
error shows up when i add Auth::user()->id

Time:08-17

this shows up when i add Auth::user()->id :

array_merge(): Expected parameter 2 to be an array, object given

here is the javascript :

var user = {!! empty(Auth::user()->id); !!};
        if (!user) {
            if (tempCart >0) {
                const pid = {!! json_encode($meterai->product_id); !!};
                const baseUrl = window.location.origin
                const url = baseUrl "/" pid "/" qty
                console.log(url)

            }else{
                alert("anda belum menentukan kuantitas meterai")
            }
        }else{
            alert("silahkan login terlebih dahulu untuk menambah keranjang")
        }

Here is the Controller :

public function index()
    {
        $this->login();
        
        if (!empty(Auth::user()->id))
            $data = $this->getPageData(Auth::user()->id);
        else
            $data = $this->getPageData(null);

        return view ('emeterai',$data);
    }

here is the error

CodePudding user response:

while returning to a view the view method accepts 2 parameters 1st is view name and second is variable/data. so in your case 2nd parameter syntax is wrong. It should be as following :

public function index()
    {
        $this->login();
        
        if (!empty(Auth::user()->id))
            $data = $this->getPageData(Auth::user()->id);
        else
            $data = $this->getPageData(null);

             return view ('path.to.the.balde.file',compact('data'));

        return view ('emeterai',compact('data'));
    }
  • Related