Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 使用搜索查询模型并将其id传递到另一个模型的最佳方法_Mysql_Sql_Laravel_Eloquent - Fatal编程技术网

Mysql 使用搜索查询模型并将其id传递到另一个模型的最佳方法

Mysql 使用搜索查询模型并将其id传递到另一个模型的最佳方法,mysql,sql,laravel,eloquent,Mysql,Sql,Laravel,Eloquent,我能得到一些帮助吗?我正在尝试以搜索方式查询我的模型数据库。获取结果时,我希望通过表单将集合的id传递到另一个模型中,而不希望使用包 到目前为止,我一直在犯错误 基本上,我是用 $services = Service::where('name' 'LIKE' Request::('input')): 但是如果我试图传递$SERVICES以查看 return view('search.result')->with($services); 它返回**非法的偏移类型** 因此,我必须详细地

我能得到一些帮助吗?我正在尝试以搜索方式查询我的模型数据库。获取结果时,我希望通过表单将集合的id传递到另一个模型中,而不希望使用包

到目前为止,我一直在犯错误

基本上,我是用

$services = Service::where('name' 'LIKE' Request::('input')):
但是如果我试图传递$SERVICES以查看


return view('search.result')->with($services);
它返回**非法的偏移类型**

因此,我必须详细地链接$services 像这样:

在我的results.blade.php上,我有:

@foreach($details as $d) 
{{$d->name}} 
<form action="{{route('book', ['id' =>$d->id} method="POST">
<button type="submit">Book</button>
</form>
@endforeach 

它告诉我这个网站上没有id 集合实例

有人能帮我找到更好的方法吗?

在你的行业:

$services=Service::where('name''LIKE'请求::('input')):

应该是:

$services = Service::where('name', 'LIKE', Request::('input'))->get();
或者,如果您希望获得类似的名称:

$services = Service::where('name', 'LIKE','%'. Request::('input').'%')->get();
在这方面:

您可以使用:

$service = Service::firstWhere('id', $id) ;
在你的队伍中:

$services=Service::where('name''LIKE'请求::('input')):

应该是:

$services = Service::where('name', 'LIKE', Request::('input'))->get();
或者,如果您希望获得类似的名称:

$services = Service::where('name', 'LIKE','%'. Request::('input').'%')->get();
在这方面:

您可以使用:

$service = Service::firstWhere('id', $id) ;

因此,要将返回集合的id传递给新模型,我必须使用


///Then, 

Book::insert([
'service_Id => $service->id]);


非常感谢大家。

因此,要将返回集合的id传递给新模型,我必须使用


///Then, 

Book::insert([
'service_Id => $service->id]);


非常感谢大家。

它在尝试获取非对象模型的属性时返回,``$service=service::findWhere('id',$id)```findWhere是可以的,但是为什么firstWhere不可以呢?它在尝试获取非对象模型的属性时返回了``$service=service::findWhere('id',$id)```findWhere是可以的,但是为什么不先在哪里呢?