I have to check a multiplication table and it gives me an error when I want to send the results to the view:
In the view:
<form action="FormTablaJuego" method="POST">
{!! csrf_field(); !!}
@for($i=0;$i<11;$i++)
{!! \Session::get('num') !!} * {!! $i !!} = <input type='text' name='caja[]' value=''><br/>
@endfor
<input type='submit' value='Comprobar' name="btncomprobar"><br/>
<input type='submit' value='Rendirse' name="btnrendirse"><br/>
</form>
In that view I collect the numbers that the user is putting.
/-------------------------------
On the controller:
public function comprobar($array) { //es llamada desde el jugar
for ($i = 0 ;$i < count($array); $i++){
if($i* \Session::get('num') == $array[$i]){
$colores[$i]='green';
}else{
$colores[$i]='red';
$perder = 1;
}
}
$datos=['usuario'=>$array,
'comprobacion'=>$colores];
return $datos;
}
public function jugar(Request $request) {
$comprobar = $request->get('btncomprobar');
$rendirse = $request->get('btnrendirse');
$usuario = $request->get('caja');
if ($comprobar == null) { //pulsó rendirse
} else {
$datos = $this->comprobar($usuario);
return view('Jugar', $datos );
}
}
And finally the view where I'm going to show the data:
<form action="FormTablaJuego" method="POST">
{!! csrf_field(); !!}
<?php for($i=0;$i<11;$i++){ ?>
{!! \Session::get('num') !!} * {!! $i !!} = <input type='text' name='caja[]' value='<?php echo usuario[$i]; ?>' style="background-color:<?php echo comprobacion[$i]; ?> " ><br/>
<?php } ?>
<input type='submit' value='Comprobar' name="btncomprobar"><br/>
<input type='submit' value='Rendirse' name="btnrendirse"><br/>
</form>
Error Page 1:
ErrorException in 1e32fa23441faa78df6cb6471d014a37 line 46:
Use of undefined constant usuario - assumed 'usuario'
1. in 1e32fa23441faa78df6cb6471d014a37 line 46
2.at HandleExceptions->handleError('8', 'Use of undefined constant usuario - assumed 'usuario'', 'C:\xampp\htdocs\ComprobarTabla\storage\framework\viewse32fa23441faa78df6cb6471d014a37', '46', array('__path' => 'C:\xampp\htdocs\ComprobarTabla\storage\framework\views/1e32fa23441faa78df6cb6471d014a37', '__data' => array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'usuario' => array('0', '4', '8', '12', '16', '20', '1', '1', '1', '1', '1'), 'comprobacion' => array('green', 'green', 'green', 'green', 'green', 'green', 'red', 'red', 'red', 'red', 'red')), 'obLevel' => '1', '__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'usuario' => array('0', '4', '8', '12', '16', '20', '1', '1', '1', '1', '1'), 'comprobacion' => array('green', 'green', 'green', 'green', 'green', 'green', 'red', 'red', 'red', 'red', 'red'), 'i' => '0')) in 1e32fa23441faa78df6cb6471d014a37 line 46
3.at include('C:\xampp\htdocs\ComprobarTabla\storage\framework\viewse32fa23441faa78df6cb6471d014a37') in PhpEngine.php line 42
4.at PhpEngine->evaluatePath('C:\xampp\htdocs\ComprobarTabla\storage\framework\views/1e32fa23441faa78df6cb6471d014a37', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'usuario' => array('0', '4', '8', '12', '16', '20', '1', '1', '1', '1', '1'), 'comprobacion' => array('green', 'green', 'green', 'green', 'green', 'green', 'red', 'red', 'red', 'red', 'red'))) in CompilerEngine.php line 58
5.at CompilerEngine->get('C:\xampp\htdocs\ComprobarTabla\resources\views/Jugar.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'usuario' => array('0', '4', '8', '12', '16', '20', '1', '1', '1', '1', '1'), 'comprobacion' => array('green', 'green', 'green', 'green', 'green', 'green', 'red', 'red', 'red', 'red', 'red'))) in View.php line 147
6.at View->getContents() in View.php line 118
The error Pág 2:
ErrorException in 1e32fa23441faa78df6cb6471d014a37 line 46:
Use of undefined constant usuario - assumed 'usuario' (View: C:\xampp\htdocs\ComprobarTabla\resources\views\Jugar.blade.php)
1. in 1e32fa23441faa78df6cb6471d014a37 line 46
2.at CompilerEngine->handleViewException(object(ErrorException), '1') in PhpEngine.php line 44
3.at PhpEngine->evaluatePath('C:\xampp\htdocs\ComprobarTabla\storage\framework\views/1e32fa23441faa78df6cb6471d014a37', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'usuario' => array('0', '4', '8', '12', '16', '20', '1', '1', '1', '1', '1'), 'comprobacion' => array('green', 'green', 'green', 'green', 'green', 'green', 'red', 'red', 'red', 'red', 'red'))) in CompilerEngine.php line 58
4.at CompilerEngine->get('C:\xampp\htdocs\ComprobarTabla\resources\views/Jugar.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'usuario' => array('0', '4', '8', '12', '16', '20', '1', '1', '1', '1', '1'), 'comprobacion' => array('green', 'green', 'green', 'green', 'green', 'green', 'red', 'red', 'red', 'red', 'red'))) in View.php line 147
5.at View->getContents() in View.php line 118
6.at View->renderContents() in View.php line 83
The table used was "4" and you can see how it takes the data well ('0', '4', '8', '12', '16', '20', '1', '1', '1', '1', '1'), These data are in the user variable that is complaining about ...
It also takes well the values of "green or red" if it is right or wrong.
Therefore I do not understand why he is giving the error.