Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lukefrost123's avatar

Empty array in URL

At the moment I am trying to format the URL of a title so that when it's clicked it displays the correct page. This involves using two seperate strings in the URL to display the page.

<a href="{{ url('brands/'.$device->bslug.'/'.$device->url)}}"></a>

Unfortunately the URL displays an empty array after sales instead of $device->bslug. It's only the URL's I have with $device->bslug in that are displaying these empty arrays.

In case there may be a problem with the controlller and/or repository that could be causing this. Here is the repository method:

  public function getAllDevicesByBrandId(Int $brandId, Bool $paginate = false){

        if ($paginate) {
            return Device::select(
            'devices.id',
            'devices.name',
            'devices.url',
            'devices.device_img',
            'brands.name as brandname',
            'brands.slug as bslug'
            )
            ->join('brands', 'devices.brand_id', 'brands.id')
            ->where(['brand_id'  => $brandId])
            ->orderBy('name')
            ->paginate(10);
        }

In the show method in the controller:

    public function show(String $brandId){
        $brands   = $this->brandRepo->getBrandBySlug($brandId);

        if ($brands) {
            return view('brands.show')->with([
                'devices'                  =>  $this->deviceRepo->getAllDevicesByBrandId($brands->id, false),
            ]);
        }
}

Was wondering where I may have gone wrong with this as it's only the slug not showing in the URL?

0 likes
1 reply
bobyrh's avatar

have u test the output of function public function getAllDevicesByBrandId ? Is it empty or not?

Please or to participate in this conversation.