H
H
HeartOfProgrammer2016-05-13 21:31:28
Laravel
HeartOfProgrammer, 2016-05-13 21:31:28

Why is my variable not found?

I'm trying to pass products from the database from the controller to the view.
controller:

public function index()
    {
        $allProducts = Product::all();

        return view('index', compact('allProducts'));
    }

view:
@foreach( $allProducts as $product )
    <img src="img/product.png" alt="..." class="image-responsive">
    <div class="caption">
    <h3>{{ $product->title }}</h3>
    <p>{{ $product->description }}</p>
    </div>
@endforeach

Routes:
Route::get('index', function() {
    return view('index');
});

And gives such error
7812ba6416704aa8ad159a61f65e9dc8.png
After all, nevertheless it is made correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Perin, 2016-05-13
@HeartOfProgrammer

You are in the route making the output of the view and not the direction to the controller action

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question