-2
route::get('about/', function(){
    return  view('about');
});

route::get('contact', function(){
    echo view('contact');
});
Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
joyonto
  • 11
  • 1
  • 3

1 Answers1

0

echo for show outputs content to the console or the web browser.

For example, `Route::get('test', function () {

$users = User::paginate(1);

echo response()->json(['users' => $users]);

});

Result,

HTTP/1.0 200 OK Cache-Control: no-cache, private Content-Type: application/json Date: Sun, 10 Jun 2018 08:06:47 GMT {"users":{"current_page":1,"data":[{"id":1,"name":"di26ek","email":"di26ek@test.com","created_at":"2018-06-06 06:15:35","updated_at":"2018-06-06 06:15:35"}],"first_page_url":"http://127.0.0.1:8000/test?page=1","from":1,"last_page":90,"last_page_url":"http://127.0.0.1:8000/test?page=90","next_page_url":"http://127.0.0.1:8000/test?page=2","path":"http://127.0.0.1:8000/test","per_page":1,"prev_page_url":null,"to":1,"total":90}} `

return for return a value or result,

For example,

Route::get('test', function () {

    $users = User::paginate(1);

    return response()->json(['users' => $users]);
});

Result,

{"users":{"current_page":1,"data":[{"id":1,"name":"di26ek","email":"di26ek@test.com","created_at":"2018-06-06 06:15:35","updated_at":"2018-06-06 06:15:35"}],"first_page_url":"http://127.0.0.1:8000/test?page=1","from":1,"last_page":90,"last_page_url":"http://127.0.0.1:8000/test?page=90","next_page_url":"http://127.0.0.1:8000/test?page=2","path":"http://127.0.0.1:8000/test","per_page":1,"prev_page_url":null,"to":1,"total":90}}

webdevtr
  • 480
  • 2
  • 6