There is a model Property.php:
class Property extends Model { protected $fillable = ['imagePath', 'title']; } Created 2 controllers:
class PropertyController extends Controller { public function getIndex() { $properties = Property::all(); return view('sh.index', ['properties' => $properties]); } } class SearchController extends Controller { public function getSearch() { $properties = Property::all(); return view('sh.search', ['properties' => $properties]); } } routes file:
Route::get('/', [ 'uses' => 'PropertyController@getIndex', 'as' => 'property.index' ]); Route::get('/search', [ 'uses' => 'SearchController@getSearch', 'as' => 'sh.search' ]); Created two identical views of search.blade.php and index.blade.php:
@extends('layouts.master') @section('content') @foreach($properties->chunk(4) as $propertyChunk) <div class="row"> @foreach($propertyChunk as $property) <div class="col-sm-6 col-md-3"> <img src="{{ $property->imagePath }}" alt="..." class="img-responsive"> <h3>{{ $property->title }}</h3> </div> @endforeach </div> @endforeach @endsection The index.blade.php view works fine, search.blade.php gives the following error:
Undefined variable: products (View: /var/www/projects/auth.laravel.com/resources/views/sh/search.blade.php) Why can't he define a variable?
PS: search.blade.php working page
layouts / master.blade.php:
<body> @include('part.header') <div class="container content-body"> @yield('content') </div> @include('part.footer') </body>
layouts.masterfor the presence of$productsand the correct transfer of this variable - Dmitriy Simushev$productsand why it is not defined. - Dmitriy Simushev