"I want to fetch data of item with id but geeting error saying missing parameter for [Route: shop.show] [URI: lord-ganesha-7514796/{id}] [Missing parameter: id]"
My Controller code is
class ECommerceController extends Controller
{
public function index(Request $request)
{
$datas = DB::select('select * from ShoppingItems');
return view('welcome',['datas'=>$datas]);
}
public function show(Request $request,$id)
{
$datas = DB::find($id);
return view('shop.show',['datas'=>$datas]);
}
Web Route is
Route::get('/','App\Http\Controllers\ECommerceController@index')->name('welcome');
Route::get('/lord-ganesha-7514796/{id}','App\Http\Controllers\ECommerceController@show')->name('shop.show');
welcome.blade.php(dashboard)
<div >
@foreach ($datas as $data)
<a href="{{ route('shop.show',['datas'=> $datas]) }}"></a>
<div >
<img src="https://thumbs.dreamstime.com/b/lord-ganesha-7514796.jpg">
<div >
{{ $data->god_name }}
</div>
</a>
@endforeach
CodePudding user response:
Edited You need to change array key from datas to id which is defined in your route:
<a href="{{ route('shop.show',['id'=> $datas]) }}"></a>
Also change DB::find() to this:
DB::table('table_name')->find($id);