【发布时间】:2017-12-06 17:29:59
【问题描述】:
当我尝试编辑数据库上的某些列(例如1)时,当我在地址栏上运行此 url 时,我正在尝试调试数据:
http://127.0.0.1:8000/content_category/1/edit
我得到了这个结果:
ContentCategories {#246 ▼
#table: "contents_categories"
#guarded: array:1 [▶]
#connection: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#attributes: []
#original: []
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
}
这个结果中的数据是null,我没有关于id=1的任何信息
这列数据存在于数据库中,我检查了phpmyadmin,我在控制器上的edit 函数是:
public function edit(ContentCategories $contentCategories)
{
dd($contentCategories);
}
和Model 在项目中:
class ContentCategories extends Model
{
protected $table = 'contents_categories';
protected $guarded = ['id'];
}
路线:
Route::resource('content_category', 'ContentCategoriesController');
【问题讨论】:
-
你能提供你的路线定义吗
-
@lagbox
Route::resource('content_category', 'ContentCategoriesController'); -
@lagbox 并发布更新
-
执行
php artisan route:list来检查它是如何定义的,它最终在URI 中使用的参数是什么?这对于隐式模型绑定很重要 -
@lagbox 我得到这个输出
content_category/{content_category}/edit | content_category.edit | App\Http\Controllers\ContentCategoriesController@edit