December 2017
Beginner to intermediate
376 pages
7h 53m
English
The last thing to do is replace the hard-coded images' URLs in the frontend app. These URLs are not currently a part of the model, so need to be manually added to the model before we inject it into the template.
We've already done a very similar job back in Chapter 4, Building a Web Service With Laravel, for the API listing route.
app/Http/Controllers/ListingController.php:
public function get_listing_api(Listing $listing) { $model = $listing->toArray(); for($i = 1; $i <=4; $i++) { $model['image_' . $i] = asset( 'images/' . $listing->id . '/Image_' . $i . '.jpg' ); } return response()->json($model); }
In fact, our web route will end up with identical code to this API route, only instead of returning JSON, it will return a view. ...
Read now
Unlock full access