1
In the Mysql Workbench the result comes out, but how to print in View?
Errorexception Array to string Conversion
public function listadepontos()
{
$id = auth()->user()->id;
$somas = DB::SELECT("select SUM(pontuacao) FROM palpite WHERE id_u = '$id' ");
return view('pontuacao')->with('somas', $somas);
}
File punctuation.php
<strong> Sua Pontuação é: <?php echo $somas;?>
</strong>
It worked that way:
@foreach($somas as $s)
<h4><strong> Sua Pontuação é: {{ $s }} </strong></h4>
@endforeach
Only once did the score appear, but I don’t think it’s the right way to code.
View would be the HTML page?
– user92257
View would be the HTML page? . php html want to print the sum into a "echo"
– Dan Even
The
Laravel
uses theBlade Engine
to work withtemplates
.– NoobSaibot
can be in tamplate Blade as well!
– Dan Even
makes a
var_dump($somas);
instead ofecho
– NoobSaibot
is there an example? array (size=1) 0 => Object(stdClass)[218] public 'soma' => string '8' (length=1) "...
– Dan Even
The line
$somas = DB::SELECT
is returning aarray
, so that you printed it on View you must change the lineview('pontuacao')->with('somas', $somas);
forview('pontuacao')->with('somas', $somas[0]);
– NoobSaibot