Reputation: 21
When I add the
Route::view('/', 'welcome');
on web.php, I've encountered this error.
(1/1) InvalidArgumentException
Attribute [view] does not exist.
in RouteRegistrar.php (line 75)
at RouteRegistrar->attribute('view', '/')in Router.php (line 1098)
at Router->__call('view', array('/', 'welcome'))in Facade.php (line 221)
at Facade::__callStatic('view', array('/', 'welcome'))in web.php (line 20)
at require('C:\\wamp64\\www\\crystalcode\\routes\\web.php')in Router.php (line 327)
at Router->loadRoutes('C:\\wamp64\\www\\crystalcode\\routes/web.php')in Router.php (line 283)
at Router->group(array('middleware' => 'web', 'namespace' => 'App\\Http\\Controllers'), 'C:\\wamp64\\www\\crystalcode\\routes/web.php')in RouteRegistrar.php (line 104)
at RouteRegistrar->group('C:\\wamp64\\www\\crystalcode\\routes/web.php')in RouteServiceProvider.php (line 56)
at RouteServiceProvider->mapWebRoutes()in RouteServiceProvider.php (line 40)
at RouteServiceProvider->map()
at call_user_func_array(array(object(RouteServiceProvider), 'map'), array())in BoundMethod.php (line 29)
at BoundMethod::Illuminate\Container\{closure}()in BoundMethod.php (line 87)
at BoundMethod::callBoundMethod(object(Application), array(object(RouteServiceProvider), 'map'), object(Closure))in BoundMethod.php (line 31)
at BoundMethod::call(object(Application), array(object(RouteServiceProvider), 'map'), array(), null)in Container.php (line 539)
at Container->call(array(object(RouteServiceProvider), 'map'))in RouteServiceProvider.php (line 74)
at RouteServiceProvider->loadRoutes()in RouteServiceProvider.php (line 33)
at RouteServiceProvider->boot()in RouteServiceProvider.php (line 28)
at RouteServiceProvider->boot()
at call_user_func_array(array(object(RouteServiceProvider), 'boot'), array())in BoundMethod.php (line 29)
at BoundMethod::Illuminate\Container\{closure}()in BoundMethod.php (line 87)
at BoundMethod::callBoundMethod(object(Application), array(object(RouteServiceProvider), 'boot'), object(Closure))in BoundMethod.php (line 31)
at BoundMethod::call(object(Application), array(object(RouteServiceProvider), 'boot'), array(), null)in Container.php (line 539)
at Container->call(array(object(RouteServiceProvider), 'boot'))in Application.php (line 788)
at Application->bootProvider(object(RouteServiceProvider))in Application.php (line 771)
at Application->Illuminate\Foundation\{closure}(object(RouteServiceProvider), 17)
at array_walk(array(object(EventServiceProvider), object(LogServiceProvider), object(RoutingServiceProvider), object(AuthServiceProvider), object(CookieServiceProvider), object(DatabaseServiceProvider), object(EncryptionServiceProvider), object(FilesystemServiceProvider), object(FormRequestServiceProvider), object(FoundationServiceProvider), object(NotificationServiceProvider), object(PaginationServiceProvider), object(SessionServiceProvider), object(ViewServiceProvider), object(AppServiceProvider), object(AuthServiceProvider), object(EventServiceProvider), object(RouteServiceProvider)), object(Closure))in Application.php (line 772)
at Application->boot()in BootProviders.php (line 17)
at BootProviders->bootstrap(object(Application))in Application.php (line 208)
at Application->bootstrapWith(array('Illuminate\\Foundation\\Bootstrap\\LoadEnvironmentVariables', 'Illuminate\\Foundation\\Bootstrap\\LoadConfiguration', 'Illuminate\\Foundation\\Bootstrap\\HandleExceptions', 'Illuminate\\Foundation\\Bootstrap\\RegisterFacades', 'Illuminate\\Foundation\\Bootstrap\\RegisterProviders', 'Illuminate\\Foundation\\Bootstrap\\BootProviders'))in Kernel.php (line 162)
at Kernel->bootstrap()in Kernel.php (line 146)
at Kernel->sendRequestThroughRouter(object(Request))in Kernel.php (line 116)
at Kernel->handle(object(Request))in index.php (line 53)
How to fix this issue, I'm beginner for the laravel please help me to set up this properly.
Upvotes: 2
Views: 5854
Reputation: 506
This is a new feature in Laravel 5.5 - it's a shortcut for calling the Route::get method with a callback that calls your view as @rafik describes.
You are probably using a previous version of Laravel, but are reading about the Route::view() shortcut in the 5.5 documents. It would actually be helpful if Laravel put a note next to new features telling since what version the feature has been available (see CakePHP documentation, php, etc).
So you need to either update your app (composer update) to the newer version of Laravel, or use a standard Route method (get, post, etc.) and call the view in a function.
Upvotes: 1
Reputation: 2101
The ROUTE works as follow :
Route::method('URL', 'Controller OR ControllerAction OR function');
// ^^^^^^ ^^^ ^^^^^^
// 1 2 3
The method you want to use to access the URL
(HTTP Method, ie.
POST
, GET
etc... and a "special" method resource
)
The url you want (ie. /home
, '/'
etc...)
If you specified the resource
method, you need to provide the name
of the controller you want to use that contains the index
,
create
, store
, edit
update
, delete
methods (you can use
php artisan make:controller myController --resource
to automatically
generate that kind of controllers. ie. HomeController
, Laravel will
automatically create for you all the route that links to these
methods with the appropriate HTTP
method.
If you specify a normal HTTP
method, you need to provide either a
function that will be called when a user access that URL, or an
Action (method in a controller) ie. MyController@MyAction
.
In your example, to simply return a view when accessing a URL :
Route::get('/', function(){
return view('welcome');
});
The route facade accepts only a valid method (the way you access to the route -- GET, POST, PUT, DELETE
-- and a resource
(which means it will automatically the four methods and link it to your controller the you specify as second argument)
Upvotes: 0