Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.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 laravel 5.2查询-htmlentities()要求参数1为字符串,对象为给定的_Mysql_Laravel_Laravel 5.2 - Fatal编程技术网

Mysql laravel 5.2查询-htmlentities()要求参数1为字符串,对象为给定的

Mysql laravel 5.2查询-htmlentities()要求参数1为字符串,对象为给定的,mysql,laravel,laravel-5.2,Mysql,Laravel,Laravel 5.2,我试图在我的网站上输出所有零售商的价格,但是当我在查询的末尾使用->get()时,它显示了这个错误 htmlentities()要求参数1为字符串,对象为给定值 代码: 但是当我使用->first()而不是->get()时,查询是成功的,并且所有内容都正确地显示在我的网站上 $price = \DB::table('cpus')->where('slug' ,'=', $slug)->join('prices', 'cpus.model', '=', 'prices.model')-

我试图在我的网站上输出所有零售商的价格,但是当我在查询的末尾使用->get()时,它显示了这个错误

htmlentities()要求参数1为字符串,对象为给定值

代码:

但是当我使用->first()而不是->get()时,查询是成功的,并且所有内容都正确地显示在我的网站上

$price = \DB::table('cpus')->where('slug' ,'=', $slug)->join('prices', 'cpus.model', '=', 'prices.model')->join('retailers', 'retailers.id', '=', 'prices.retailer_id')->select('prices.price', 'prices.url')->first();
如何显示所有记录而不是一条记录,使用->get()会有什么问题

控制器:

$price = \DB::table('cpus')->where('slug' ,'=', $slug)->join('prices', 'cpus.model', '=', 'prices.model')->join('retailers', 'retailers.id', '=', 'prices.retailer_id')->select('prices.price', 'prices.url')->first();

    $data = [
          'price' => $price
          ];
     return view('part', $data);
看法


基本上,foreach中的两个值中有一个或多或少是数组etc,而不是字符串

通过在foreach之后添加
{{{dd()}}
来调试它,以获取其输出的值,查看结果是什么。类似于

 @foreach ($price as $p => $value)

      {{dd($p)}}    

    <h5> {{$p}}</h5> <br>
    <p>{{$value}}</p>
 @endforeach

但是先看看dd生产的etc的模型<代码>获取获取一个集合。您显示的代码不是问题所在,我不相信,问题出在您使用
$price
的控制器或视图中。显示给我们看。用视图和控制器更新问题,我在哪里使用$price我不认为你的错误在那里,无论如何,你使用的是LaraveCollective吗?比如{{HTML::}}?我不使用它,只使用普通的旧HTML。我添加了完整的eror,也许这有助于解决问题。你能发布完整的控制器方法和完整的视图页面吗?我并没有完全理解你刚才想说的,但是{dd($p}}}的输出只是'0'和{dd($value)}的输出这样可以吗,所以$value的值是一个数组,所以需要像{{{$value->price}一样输出它

为了避免实体错误,因为它无法解析数组,希望这有助于避免看到您在上面编辑了答案,现在我也得到了答案,它像多维数组一样输出。我只需要使用2个循环来输出它。非常感谢m8帮助我:)
@foreach ($price as $p => $value)
<h5> {{$p}}</h5> <br>
<p>{{$value}}</p>
@endforeach
    in helpers.php line 531
at CompilerEngine->handleViewException(object(ErrorException), '1') in PhpEngine.php line 44
at PhpEngine->evaluatePath('C:\xampp\htdocs\laravel\storage\framework\views/c6f0b1264595e5a7c0dccbaeda0b9c53ec2bb0a2.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'title' => 'Intel Core i3-4170 - BX80646I34170', 'part_name' => 'Intel Core i3-4170 3.7GHz 2-kodolu procesors', 'specs' => object(stdClass), 'img' => array(object(stdClass), object(stdClass)), 'price' => array(object(stdClass), object(stdClass)))) in CompilerEngine.php line 59
at CompilerEngine->get('C:\xampp\htdocs\laravel\resources\views/part.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'title' => 'Intel Core i3-4170 - BX80646I34170', 'part_name' => 'Intel Core i3-4170 3.7GHz 2-kodolu procesors', 'specs' => object(stdClass), 'img' => array(object(stdClass), object(stdClass)), 'price' => array(object(stdClass), object(stdClass)))) in View.php line 149
at View->getContents() in View.php line 120
at View->renderContents() in View.php line 85
at View->render() in Response.php line 53
at Response->setContent(object(View)) in Response.php line 199
at Response->__construct(object(View)) in Router.php line 1087
at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack(object(cpuController), object(Route), object(Request), 'showCpu') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\cpuController', 'showCpu') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 724
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Router.php line 726
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 53
 @foreach ($price as $p => $value)

      {{dd($p)}}    

    <h5> {{$p}}</h5> <br>
    <p>{{$value}}</p>
 @endforeach
   $value->price