我的计划如下。 我有这个内心联盟:
SELECT cd.fk_lend_id,cd.serialnumber ,customers.name,cd.created_at
FROM cd
INNER JOIN customers ON cd.fk_lend_id = customer.lend_id
Where cd.fk_lend_id = 00000000;
这就是Laravel的样子:
$scores = DB::table('cd')
->join('cd', 'cd.fk_lend_id', '=', 'customer.lend_id')
->select('cd.fk_lend_id','cd.serialnumber','users.name', 'cd.created_at')
->where('cd.fk_lend_id',00000000)
->get();
(created_at代表客户借出CD的时间)
- > where('cd.fk_lend_id',00000000)< - 应该用来自视图的输入字段的用户输入替换零,并且在输入之后应该重定向这是否可能?
如果有可能有人可以给我建议怎么做?
(编辑)
“yourcds”功能:
public function yourcds(Request $request, cds $cd)
{
$this->middleware('guest');
$user_input = $request->userInput
$scores = DB::table('cd')
->join('customers', 'cd.fk_lend_id', '=', 'customer .lend_id')
->select('cd.fk_lend_id','cd.serialnumber','users.name', 'cd.created_at')
->where('cd.fk_lend_id',$request->$user_input)
->get();
$cds = cd::latest()->paginate(20);
return view('cd.yourcds',compact('cd'))
-> with('i', (request()->input('page', 1) - 1) * 20);
}
“返回”功能:
public function return(cds $cd)
{
return view('cd.return',compact('cd'));
}
答案 0 :(得分:1)
只需添加
->join('cd', 'cd.fk_lend_id', '=', 'customer.lend_id')
应该是
->join('customers', 'cd.fk_lend_id', '=', 'customer.lend_id')
答案 1 :(得分:1)
function <controller-name>(Request $request){
$myfield = $request->input('<formfieldname>');
$scores = DB::table('cd')
->join('cd', 'cd.fk_lend_id', '=', 'customer.lend_id')
->select('cd.fk_lend_id','cd.serialnumber','users.name', 'cd.created_at')
->where('cd.fk_lend_id',$myfield)
->get();
}
答案 2 :(得分:1)
首先,您必须使用
获取用户输入$user_input = $request->userInput
然后,只需输入你的where子句
$scores = DB::table('cd')
->join('cd', 'cd.fk_lend_id', '=', 'customer.lend_id')
->select('cd.fk_lend_id','cd.serialnumber','users.name', 'cd.created_at')
->where('cd.fk_lend_id', $userInput)
->get();
那就是它,不需要引号
修改强>
使用您的函数返回带有窗体的视图:
public function return(cds $cd) {
return view('cd.return',compact('cd'));
}
定义到yourcds()方法的路线:
Route::post('/yourcds', 'ControllerName@youcds');
在cd.return文件中,就像这样
<form action="/yourcds" method="POST">
@csrf
<input type="text" name="userInput" >
<input type="submit" value="submit" >
</form>
在您的方法中,yourcds()palce参数Requsest:
public function yourcds(Request $request) {
$this->middleware('guest');
$user_input = $request->userInput
$scores = DB::table('cd')
->join('customers', 'cd.fk_lend_id', '=', 'customer .lend_id')
->select('cd.fk_lend_id','cd.serialnumber','users.name', 'cd.created_at')
->where('cd.fk_lend_id',$request->$user_input)
->get();
$cds = cd::latest()->paginate(20);
return view('cd.yourcds',compact('cd'))
-> with('i', (request()->input('page', 1) - 1) * 20);
}
希望得到答案