Estoy viendo en youtube un curso para aprender laravel, pero me atoré en uno de los videos, me marca el siguiente error:
Whoops, looks like something went wrong. 2/2
ErrorException in 64985b6b79521ec2a9edfc6aab57cf2831fffa17.php line 63: Undefined property: stdClass::$idarticulo (View: C:\CursoLaravel\sisVentas\resources\views\compras\ingreso\create.blade.php)
in 64985b6b79521ec2a9edfc6aab57cf2831fffa17.php line 63
at CompilerEngine->handleViewException(object(ErrorException), '1') in PhpEngine.php line 44
at PhpEngine->evaluatePath('C:\CursoLaravel\sisVentas\storage\framework\views/64985b6b79521ec2a9edfc6aab57cf2831fffa17.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'personas' => array(object(stdClass)), 'articulos' => array(object(stdClass)))) in CompilerEngine.php line 59
at CompilerEngine->get('C:\CursoLaravel\sisVentas\resources\views/compras/ingreso/create.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'personas' => array(object(stdClass)), 'articulos' => array(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 201
at Response->__construct(object(View)) in Router.php line 1085
at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 94
Y muchas líneas más. Hay otro error (me parece que es lo mismo)
1/2
ErrorException in 64985b6b79521ec2a9edfc6aab57cf2831fffa17.php line 63:
Undefined property: stdClass::$idarticulo
in 64985b6b79521ec2a9edfc6aab57cf2831fffa17.php line 63
at HandleExceptions->handleError('8', 'Undefined property: stdClass::$idarticulo', 'C:\CursoLaravel\sisVentas\storage\framework\views\64985b6b79521ec2a9edfc6aab57cf2831fffa17.php', '63', array('__path' => 'C:\CursoLaravel\sisVentas\storage\framework\views/64985b6b79521ec2a9edfc6aab57cf2831fffa17.php', '__data' => array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'personas' => array(object(stdClass)), 'articulos' => array(object(stdClass))), 'obLevel' => '1', '__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'personas' => array(object(stdClass)), 'articulos' => array(object(stdClass)), 'persona' => object(stdClass), 'articulo' => object(stdClass))) in 64985b6b79521ec2a9edfc6aab57cf2831fffa17.php line 63
at include('C:\CursoLaravel\sisVentas\storage\framework\views\64985b6b79521ec2a9edfc6aab57cf2831fffa17.php') in PhpEngine.php line 42
at PhpEngine->evaluatePath('C:\CursoLaravel\sisVentas\storage\framework\views/64985b6b79521ec2a9edfc6aab57cf2831fffa17.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'personas' => array(object(stdClass)), 'articulos' => array(object(stdClass)))) in CompilerEngine.php line 59
at CompilerEngine->get('C:\CursoLaravel\sisVentas\resources\views/compras/ingreso/create.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'personas' => array(object(stdClass)), 'articulos' => array(object(stdClass)))) in View.php line 149
at View->getContents() in View.php line 120
Lo poco que puedo entender es que, por alguna razón, no encuentra el $idarticulo, pero de acuerdo al código escrito, sí está ahí (sale de un foreach)
<div class="panel panel-primary">
<div class="panel-body">
<div class="col-lg-3 col-sm-3 col-md-3 col-xs-12">
<div class="form-group">
<label>Artículo</label>
<select name="pidarticulo" class="form-control selectpicker" id="pidarticulo" data-live-search="true">
@foreach($articulos as $articulo)
<option value="{{$articulo->idarticulo}}">{{$articulo->articulo}}</option>
@endforeach
</select>
</div>
</div>
</div>
</div>
La variable $articulos
se manda desde el controlador en la función "create":
public function create()
{
$personas=DB::table('persona')->where('tipo_persona','=','Proveedor')->get();
$articulos=DB::table("articulo")
->select(DB::raw('CONCAT(codigo, " ",nombre) as articulo', 'idarticulo'))
->where('estado','=','Activo')
->get();
return view('compras.ingreso.create',["personas"=>$personas,"articulos"=>$articulos]);
}
Ya le di vueltas al código varias veces y no encuentro qué es lo que estoy haciendo mal. ¿Podrían echarle un vistazo, a ver si dan con la solución? No pegué todo el código porque me parece que es demasiado, pero si necesitan más info edito el tema.
¡Gracias!
->select(DB::raw('CONCAT(codigo, " ",nombre) as articulo', 'idarticulo'))
tendría que ser->select(DB::raw('CONCAT(codigo, " ",nombre) as articulo'), 'idarticulo')