Home > Enterprise >  how to display data based on specific id in laravel?
how to display data based on specific id in laravel?

Time:11-24

I am new to laravel. I want to send data as id of existing data. Id comes from products.blade I send via href tag as shown below to gallery page. I have tried to find a way through other sites but it still doesn't work

<a  href="/dashboard/galleries/{{ $product->id }}"><i ></i></a>

then i create a route like this

Route::resource('/dashboard/galleries', DashboardGalleryController::class)->middleware('admin')->shallow();

in the controller gallery, I made like this

public function index($id)
    {
        $gallery = Gallery::where('products_id', $id)->get();
        return view('dashboard.galleries.index', compact('gallery'));
    
    }

then inside the gallery page, I want to display a table to add images based on that id.

dashboard/galleries/index.blade.php

<h1>{{ $gallery->id }}</h1>

should i add data inside foreach or outside?

CodePudding user response:

A restful resource controller sets up some default routes for you and even names them. and ur case the logic should be inside show() function not index()

check this issue it will help u same issue solved here

  • Related