Here I have two folder named products and teamname. In team name, I have index.blade.php where I can view name like this using this code
<td>{{ $teambatter->name }}</td>
Where TeambatterController.php have this code
public function index()
{
$teambatter = Teambatter::latest()->paginate(5);
return view('teambatters.index',compact('teambatter'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
The problem is when I view same name in indexpublic.blade.php in products folder using this code
<h1> {{ $teambatter->name }} </h1>
I got $teambater is undefine in indexpublic.blade.php. How can I add this name to indexpublic.blade.php in the products folder?
its not working If I pass like this in my productConteroller.php
public function indexpublic()
{
$teambatter = Teambatter::latest()->paginate(20);
$products = Product::latest()->paginate(20);
return view('products.indexpublic',compact('products'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
This is my web.php
Route::get('/', [ProductController::class, 'indexpublic']);
CodePudding user response:
In the indexpublic() function you're passing the $products variable to the view, but not the $teambatter variable.
This should work:
public function indexpublic()
{
$teambatter = Teambatter::latest()->paginate(20);
$products = Product::latest()->paginate(20);
return view('products.indexpublic',compact('products', 'teambatter'))->with('i', (request()->input('page', 1) - 1) * 5);
}