如果正在填写laravel表单,我正在尝试使用select语句。我有2个表“查询” 和“全部” 。如果用户填写表单,则将其保存在查询中,但我还希望它从表 all 中选择某些字段并返回答案。
用户填写表单后,现在保存在查询中。
$post = new query;
$post->name = $request->input('name');
$post->description = $request->input('description');
$post->email = auth()->user()->email;
$post->save();
session()->flash('notif', "Query has been submitted succesfully");
$check = check::select('all.*')
->where('name', '=', $post->name)
->get();
答案 0 :(得分:0)
如果我了解您的问题,则需要从all
表中获取结果,其中“名称”为$post->name
。如果是这样,请检查以下内容:
$post = new query;
$post->name = $request->input('name');
$post->description = $request->input('description');
$post->email = auth()->user()->email;
$post->save();
session()->flash('notif', "Query has been submitted succesfully");
$check = DB::table('all')
->where('name', $post->name)
->get();
请不要忘记将use DB;
放在控制器的顶部
答案 1 :(得分:0)
我无法理解check
中的check::select()
是什么。但是我从查询中得到的是,您想在表“查询” 中插入数据后,从表“全部” 中选择特定字段。
所以您可以这样做以达到我的理解。
$post = new query;
$post->name = $request->input('name');
$post->description = $request->input('description');
$post->email = auth()->user()->email;
$post->save();
// use any of the following
$check = all::where('name', $post->name)->get(); // SELECT *
$check = all::where('name', $post->name)->get(['field1', 'field2']); // SELECT 'specific'
session()->flash('notif', "Query has been submitted succesfully");