【发布时间】:2017-05-22 21:38:39
【问题描述】:
这是我的路线:
Route::get('/', 'StoreController@mainSite');
Route::get('/product/{id_product}', 'StoreController@showProduct');
Route::get('/kontact', 'StoreController@showContaktForm');
Route::get('/login', 'AuthController@formView')
Route::post('/login', 'AuthController@login');
Route::get('/logout', 'AuthController@logout');
Route::get('/register', 'RegisterController@formView');
Route::post('/register', 'RegisterController@register');
Route::get('/panel', 'PanelController@mainSite');
Route::get('/panel/data', 'PanelController@formView');
Route::post('/panel/data', 'PanelController@updateData');
Route::get('/panel/orders', 'OrderController@showOrders');
Route::post('/panel/orders/add', 'OrderController@addOrder');
Route::post('/cart/add', 'CartController@addItem');
Route::post('/cart/remove', 'CartController@removeItem');
Route::get('/cart', 'CartController@showItems');
Route::get('/{categoryName}', 'StoreController@showCategory');
Route::get('/{categoryName}/{subcategoryName}','StoreController@showSubcategory');
现在我的视图代码链接中可以将商品添加到我的购物车:
<h4><a class="shopBtn" href="/cart/add" title="add to cart"> Add to cart </a> </h4>
但是,当我点击这个时,我给出了警告:
ErrorException in Category.php line 16:
Trying to get property of non-object
而且我认为,这个类别不需要,我想,这个 href 正在进入他的路线:
Route::get('/{categoryName}', 'StoreController@showCategory');
是否有可能修复它?也许将动作添加到href? 我很确定在我的错误中调用的这个模型与我现在想做的事情无关。
我的类别模型:
class Category extends Model
{
protected $table = 'zoo';
public $timestamps = false;
public function getCategoryId($name)
{
$category = Category::select('id')->where('name', $name)>first();
return $category->id;
}
}
但是我的 CartController 应该返回给我这个视图
public function addItem()
{
return View('cart');
}
而且我认为它无论如何都不会到达这里
【问题讨论】:
-
Category.php的内容是什么?那是你的StoreController吗? -
/cart/add正在等待一个 post 请求,你并通过a href传递一个 get 请求 -
我认为您正在尝试在不存在的地方获得价值,您可以分享 category.php 代码吗?
-
我在帖子中添加所有内容(已编辑帖子)