public function index() { $orders = App\Order::all(); foreach ($orders as $order) { $customer = App\Customer::find($order->customer_id); echo $order->name . " Ordered by " . $order->customer->name . "<br/>"; } }
<?php /* |-------------------------------------------------------------------------- | Routes File |-------------------------------------------------------------------------- | | Here is where you will register all of the routes in an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', function () { return view('welcome'); }); Route::get('customer', function () { $customer = App\Customer::find(1); echo 'Hello my name is ' . $customer->name; }); /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | This route group applies the "web" middleware group to every route | it contains. The "web" middleware group is defined in your HTTP | kernel and includes session state, CSRF protection, and more. | */