[英]Laravel Data passing from view to controller
我需要将数据从视图文件传递到控制器文件。 目的是在编辑记录时向用户显示以前的数据。 我的视图文件包含以下代码:
<a href="{{ route('feestype.edit', $feesType) }}" class="btn btn-info btn-sm">Edit</a>
在将其传递给控制器之前,我先调用了dd方法。 这是dd的结果:
FeesType {#287 ▼
#table: "fees_types"
#fillable: array:2 [▶]
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:5 [▶]
#original: array:5 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
}
当我在控制器文件中收到对象时,它将在dd上显示此结果:
FeesType {#283 ▼
#table: "fees_types"
#fillable: array:2 [▶]
#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: []
#guarded: array:1 [▶]
}
问题是连接变量在控制器中返回空值,但在视图中它返回了我当前的连接数据库:mysql。 这是我的控制器文件的编辑方法:
public function edit(FeesType $feesType)
{
//
//$feesType = FeesType::find($feesType->id);
dd($feesType);
return view('feestype.edit',['feesType'=>$feesType]);
}
这是我的路线定义:
Route::resource('feestype','FeesTypesController');
我不知道背后的原因。 有人可以帮我吗?
尝试这样:
路线
<a href="{{ route('feestype.edit', $feesType->id) }}" class="btn btn-info btn-sm">Edit</a>
控制器
public function edit($id)
{
$feesType = \App\FeesType::find($id);
dd($feesType);
return view('feestype.edit',['feesType'=>$feesType]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.