我有2个简单的观看次数:sqrt(biganalytics::colsum(x*x))
和home
。这是他们的控制器
create
和路线
public function index()
{
$products = Product::all();
return view('home', compact('products'));
}
public function createProduct()
{
return view('productCreate');
}
public function createProductSubmit( Request $request ) {
$product = new Product;
$product->productName = $request->name;
$product->productPrice = $request->price;
$product->quantity = strip_tags($request->quantity);
$product->category_id = $request->category;
$product->save();
return view('home');
}
问题在于,当我进入Route::get('/home', 'HomeController@index');
Route::get('/home/product/create', 'HomeController@createProduct');
Route::post('/home/product/create', 'HomeController@createProductSubmit');
创建新产品时,在我添加所有内容并提交表单后,我收到了错误
未定义的变量:home.blade.php中的产品
为什么我收到此错误?在我的/home/product/create
函数中,我传递了它?
更新
index()
答案 0 :(得分:3)
更改以下行:
$product->save();
return view('home');
到
$product->save();
return redirect('/home'); // or what ever route you want