Есть модель Property.php:
class Property extends Model {
protected $fillable = ['imagePath', 'title'];
}
Создал 2 контроллера:
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:
Route::get('/', [
'uses' => 'PropertyController@getIndex',
'as' => 'property.index'
]);
Route::get('/search', [
'uses' => 'SearchController@getSearch',
'as' => 'sh.search'
]);
Создал две одинаковых вьюхи search.blade.php и 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
Вьюха index.blade.php отрабатывает нормально, search.blade.php выдает такую ошибку:
Undefined variable: products (View: /var/www/projects/auth.laravel.com/resources/views/sh/search.blade.php)
Почему он не может определить переменную?
П.С.: страница search.blade.php рабочая
layouts/master.blade.php:
<body>
@include('part.header')
<div class="container content-body">
@yield('content')
</div>
@include('part.footer')
</body>
layouts.master
на наличие$products
и правильную передачу этой переменной$products
и почему он не определен.