Problems sending items to my view

0

I'm having problems sending collections to my blade view. in my controller I have implemented the index function in this way:

public function index(Request $request)
    {
        $productos = Producto::latest()
                    ->take(5)
                    ->get();

        $clientes = Clientes::latest()
            ->take(5)
            ->get();

        $proveedores = Proveedor::latest()
            ->take(5)
            ->get();


        $facturas = Factura::latest()
                    ->take(5)
                    ->get();

        $facturas_canceladas = Factura::latest()
            ->take(5)
            ->get();

        //DETERMINAR LOS PRODUCTOS MAS SOLICITADOS

        $ventas = Producto::withCount('ventasProductos')
                            ->orderBy('ventas_productos_count', 'desc')
                            ->take(5)
                            ->get();

        return view('home')->with('productos', $productos)->with('facturas_canceladas', $facturas_canceladas)
                           ->with('facturas', $facturas)->with('ventas', $ventas)->with('clientes', $clientes)
                           ->with('proveedores', $proveedores);

but this error throws me:

Undefined variable: ventas (View: C:\xampp\htdocs\productos_ventas2\resources\views\home.blade.php)

Check in my view and the sales variable is well set. If I delete this variable, I drag the error to the other variable that follows it, which is clients etc.

    
asked by albertolg89 13.04.2018 в 16:48
source

1 answer

0

Resolved, explain what the error was:

On my route I had the following route implemented:

Route::get('/', function () {
        return view('home');
    });

This did not shoot against any controller and that was the problem. Then I defined the route well and ready:

Route::get('/', 'HomeController@index')->name('home');
    
answered by 13.04.2018 в 17:07