Laravel 5 Helloworld controller and view

You want to access a url localhost:8000/helloworld like this.

<li><a href="{{ url('/helloworld') }}">Hello</a></li>

1. Add this in app/Http/routes.php

Route::get('/helloworld', 'HelloworldController@index');

2. Create controller php class in app/Http/Controllers/HelloworldController.php

namespace App\Http\Controllers;

use App\Http\Requests;
use Illuminate\Http\Request;

class HelloworldController extends Controller

    protected $message;

     * Create a new controller instance.
     * @return void
    public function __construct()
        $this->message = "Hey, you've made a hello world controller view in Laravel 5!";

     * Show the helloworld page.
     * @param  Request  $request
     * @return \Illuminate\Http\Response
    public function index(Request $request)
        return view('helloworld', [
            'message' => $this->message;

3. Create a view file in resources/views/helloworld.blade.php

    <div class="container">
        <div class="col-sm-offset-2 col-sm-8">
            <div class="alert alert-success" role="alert">{{ $message }}</div>

4. Go to localhost:8000/helloworld in a browser, replace the 8000 with the port number you use. You should see:

Search within Codexpedia

Custom Search

Search the entire web

Custom Search