Dawood Najam
Dawood Najam

Reputation: 503

View not loading when called from a Controller in Laravel

I created a controller using artisan in my Laravel application, here's the code:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class NavigationController extends Controller {

    public function welcome() {
        return view("welcome");
    }

}

When I use a Closure or load the view directly, everything works fine. But, when I load view from inside a controller, it couldn't find it. Here's my web.php file's code:

Route::get('/', function () {
    return view('NavigationController@welcome');
});

The error it shows:

InvalidArgumentException View [NavigationController@welcome] not found:

image

Upvotes: 0

Views: 745

Answers (1)

leofgea
leofgea

Reputation: 91

It's because the view NavigationController@welcome doesn't exist, this is a method.

Either you load the view from the closure :

Route::get('/', function() {
    return view('welcome');
});

Either you call a method of the controller and this method loads the view:

Route::get('/', 'NavigationController@welcome');

Please see: Laravel Routing documentation

Upvotes: 1

Related Questions