【发布时间】:2021-08-05 10:35:08
【问题描述】:
对于我的 laravel 项目,我创建了产品类别表并将数据添加到表中。现在我需要使用 get 方法获取每个 product_category 详细信息。
这是我创建的产品类别表,
public function up()
{
Schema::create('p_categories', function (Blueprint $table) {
$table->bigIncrements('category_id');
$table->string('name');
$table->string('size');
$table->timestamps();
});
}
我使用的CategoryController,
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\PCategory;
class CategoryController extends Controller
{
//
function addPCategory(Request $req)
{
$pcategory=new PCategory;
$pcategory->name=$req->input('name');
$pcategory->size=$req->input('size');
$pcategory->save();
return $pcategory;
}
function getCategory($id)
{
return PCategory :: find($id);
}
}
在我使用的 api.php 中,
Route :: post('addPCategory',[CategoryController::class,'addPCategory']);
Route :: get('Category/{id}',[CategoryController::class,'getCategory']);
我在邮递员中收到此错误
Illuminate\Database\QueryException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'p_categories.id' in 'where clause' (SQL: select * from `p_categories` where `p_categories`.`id` = 1 limit 1)
提前感谢您的帮助!
【问题讨论】:
-
这和javascript有什么关系?
标签: javascript json laravel api postman