laravel - 在 laravel 上的创建功能上传递 ID 中找不到视图
问题描述
我想通过user_id
创建页面。
我的controller
public function create($user)
{
$loanAmount=LoanAmount::all()->pluck('amount','id');
$userId=User::where('id',$user)->pluck('id')->first();
// $user->id;
// dd($user);
return view('loan/grant-loan-amounts/create/'.$userId)
->with($userId)
->with($loanAmount);
}
这是我的route
Route::resource('loan/grant-loan-amounts', 'Loan\\GrantLoanAmountsController',[
'except' => ['create']
]);
Route::get('loan/grant-loan-amounts/create/{userId}', 'Loan\\GrantLoanAmountsController@create')->name('grant-loan-amounts.create');
我将创建页面设为空白。只有“asd”才能显示。
我想要实现的是,从用户文件夹中的用户列表中,我将通过授予贷款金额的用户 ID 创建一个页面。但我无法弄清楚为什么找不到路线。
有什么建议吗?
解决方案
不要在view()
函数的第一个参数中传递 id。仅在视图函数的第一个参数中提及视图文件。compact()
将所有带函数的变量作为 的第二个参数传递view()
。例子:
public function create($user)
{
$loanAmount=LoanAmount::all()->pluck('amount','id');
$userId=User::query()->findOrFail($user)->id;
return view('user.create',compact('userId','loanAmount')) //in this example 'user' is the folder and 'create' is the file inside user folder
}
推荐阅读
- javascript - Javascript:如何分隔字符串中的字节
- excel - Robot Framework:将 SQL 结果保存到 excel
- c++ - 虚函数调用的编译器优化
- powershell - 如何在 PowerShell 模块中使用常量?
- oracle11g - 在 Oracle SQLdeveloper(4.1.3.20) 中执行 SQL 脚本文件列表
- ios - gomobile:绑定 ObjC 的回调
- javascript - React 从数组中获取值 og 键
- mysql - MySQL ...根据另一个表的查询从一个表中删除记录
- iframe - 如何调整嵌入式议程上的默认“显示事件直到”
- java - Java 中的身份验证 URL