There is a Search page (1) I click on the selected item and go to the propertyprofile page (2). I get this error when going:

Undefined index: imagePath(View: /var/www/projects/auth.laravel.com/resources/views/sh/propertyprofile.blade.php) 

routes / web.php file:

 Route::get('/search', [ 'uses' => 'SearchController@getSearch', 'as' => 'sh.search' ]); Route::get('/search/propertyprofile', [ 'uses' => 'PropertyProfileController@getPropertyProfile', 'as' => 'sh.search.propertyprofile' ]); 

SearchController and PropertyProfileController files:

 class SearchController extends Controller { public function getSearch() { $properties = Property::all(); return view('sh.search', ['properties' => $properties]); } } class PropertyProfileController extends Controller { public function getPropertyProfile() { $properties = Property::all(); return view('sh.propertyprofile', ['properties' => $properties]); } } 

Property model:

 class Property extends Model { protected $fillable = ['imagePath', 'title', 'description', 'price', 'id']; } 

search.blade.php:

 @extends('layouts.master') @section('content') @foreach($properties->chunk(4) as $propertyChunk) <div class="row"> @foreach($propertyChunk as $property) <div class="col-md-3"> <img src="{{ $property->imagePath }}" alt="..." class="img-responsive"> <h3>{{ $property->title }}</h3> <a href="{{ route('sh.search.propertyprofile') }}">Property Profile</a> </div> @endforeach </div> @endforeach @endsection 

file propertyprofile.blade.php:

 @extends('layouts.master') @section('content') <img src="{{ $properties['imagePath'] }}" alt="..." class="img-responsive"> <h3>{{ $properties['title'] }}</h3> <!-- <p> Hello world! </p> --> @endsection 

And when in propertyprofile.blade.php in @section you write just Hello world, then it goes without problems ... Help me figure it out, because I’m equally lifting values ​​from an array in two views .... WHAT is wrong with me?

    2 answers 2

    how do getPropertyProfile know that you clicked on this book? You have the same getSearch () and getPropertyProfile () that you want to achieve this?

    https://laravel.com/docs/5.4/routing#route-parameters

    Like that

     Route::get('/search/propertyprofile/{item_id}', [ 'uses' => 'PropertyProfileController@getPropertyProfile', 'as' => 'sh.search.propertyprofile' ]); class PropertyProfileController extends Controller { public function getPropertyProfile($item_id,Request $request) { $properties = Property::where('item_id', $item_id); return view('sh.propertyprofile', ['properties' => $properties]); } } 

    In the view millet make $ properties-> imagePath etc.

    • Asets, thanks a lot, but I still get the error 500: Undefined property: Illuminate \ Database \ Eloquent \ Builder :: $ imagePath (View: /var/www/projects/auth.laravel.com/resources/views/sh/propertyprofile. blade.php) - Alexander
     Route::get('/search/propertyprofile/{item_id}', [ 'uses' => 'PropertyProfileController@getPropertyProfile', 'as' => 'sh.search.propertyprofile' ]); class PropertyProfileController extends Controller { public function getPropertyProfile($item_id,Request $request) { $properties = Property::where('item_id', $item_id) ->first(); return view('sh.propertyprofile', ['properties' => $properties]); } } 

    Here I figured it out, Asets, you pushed me right in the right direction, but as it turned out, you also needed to add a method -> first () !!!