如何将laravel数据从控制器传递到视图而不会获得未定义的变量产品?将Laravel的控制器数据传递给视图
控制器:
public function postSearch(Request $request){
$text = $request->input('txtsearch');
$products = DB::table('products')->where('title', 'Like', $text)->get();
return redirect()->route('product.search', ['products' => $products]);
}
查看:
@extends('Layout.master')
@section('content')
@foreach($products as $product)
{{$product->title}}
@endforeach
@endsection
我没有看到“名”有一个变量? – aimme
更新了我的问题。 – steven
代码似乎是正确的..但你可能会在错误的观点 – aimme