Laravel Controller not adding to route list - php

I created a new controller with resources using the PHP artisan command:
php artisan make:controller AdminCategoriesController --resource
The file gets added to the controller folder but when I visit my route list with I see no route about it:
php artisan route:list
Here my routes list:
How can I add the categories to my routing list?

This error is showing because you did not give instance of Resource Controller in web.php file.
Route::resource('route','AdminCategoriesController ');
When you did this , route list will show.

I failed to add the route resource in my routes.php
Route::resource('/admin/categories', 'AdminCategoriesController');
Everything works now.

If you are using api then use this syntax to generate controller
php artisan make:controller API/PhotoController --api

Related

Laravel : command php artisan route:list generates an error : AuthController not found

I am working in a laravel project running version 5.6.39. When I try to run a command php artisan route:list, it generates an error saying "ReflectionException : Class App\Http\Controllers\Auth\AuthController does not exist".
routes\web.php looks like...
How can I resolve this issue? Please help.
Thank You.
The reason behind this issue is when you run php artisan route:list laravel reads all routes from routes folder and executes every controller that exists in them and if laravel couldn't find the controller or there is an error in them laravel throws an exception
so with that in mind it means you either removed App\Http\Controllers\Auth\AuthController or you moved it to another folder but didn't update the AuthController namespace and also the namespace in web.php so in your case you need to fix namespace in web.php and also in controller until they match

Laravel: Routing & Controller

I'm a beginner using this laravel framework. Currently i'm trying to understand the routing and controller of this framework.
I created a controller file using this command:
php artisan make:controller Admin/PostController
Of course the output of this is to create a controller file inside Admin folder. Inside of the PostController.php i wrote a code like this:
public function create()
{
return view('admin.post.post');
}
Also, in my web.php i have this code.
Route::get('/', function () {
return view('user.blog');
});
Route::get('posts',function(){
return view('user.posts');
})->name('posts');
Route::resource('admin/post','Admin\PostController');
The "admin" is a folder and the "post" is a folder too inside the "admin" and when you open the "post" folder you'll see the "post.blade.php" file. The other two route::get in my web.php are working fine. But the route:resource is not working.
When i tried to run this in my browser using this link:
localhost:8000/admin/post/create
The browser says: Sorry, the page you are looking for could not be found
Is there any problem with syntax or path structures?
Here's my post.blade.php
#extends('admin.layouts.app')
#section('main-content')
this is just html codes..
#endsection
Here's my php artisan route:list
this because some time composer stuck, for that times you should stop serve and re generate autoload
1.stop your php artisan serve
2.enter this command
composer dumpautoload
3.run your php artisan serve

Change php artisan make:controller resource layout

When we use
php artisan make:controller --resource
a controller with basic functions is created.
I want to change this code to add more functions that all controllers will use.
How to change the default resource code?
Thank's to #teeyo I was able to make a new search and found this:
https://blog.vigilantmedia.com/2015/08/07/how-to-customize-controllers-generated-by-artisan-in-laravel/

Laravel can't find method

I have a GET request to:
/review/response
The route is present in the php artisan route:list with other two working routes to that controller, so controller is fine.
Here is a part of my controller code:
But when accessing to that route, this is the response I get:
I already run composer du and php artisan route:clear
All other methods in that controller are working, any idea?
Your namespace should be following :
namespace App\Http\Controllers
I believe your route should be like:
Route::get('review/response', ['as' => 'review.action', 'uses' => 'App\Http\Controllers\Admin\ReviewController#action']);
The problem is in your namespace. Give it a try.

The HomeController default on laravel doesn't exist

I am new on laravel, and I am making some test and following a tutorial. The matter is that I don´t know what I did two days ago that I got any defaults controllers (maybe only one... I don´t remember, for example: HomeController). I removed the project and create a new one... but now these defaults controllers don´t exit. And my routes.php on app/http folder is like this:
Route::get('/', function () {
return view('welcome');
});
ONLY THIS!!!
I remember that the routes.php file of the first laravel test project had something like: get("home")... or get("login"), etc...
Do I need to install them via artisan or something?
When installing Laravel, i. e. with this command composer create-project --prefer-dist laravel/laravel blog, there is no app/Http/Controller/HomeController.php generated.
You only get one route in your routes.php. That's it!
What you could do, of course, is:
Create a class HomeController.php in app/Htpp/Controllers - use php artisan make:controller HomeController
Change the route in your routes.php to utilize the new HomeController
Route::get('/', 'HomeController#index');
Another thing you may did in the past was running php artisan make:auth to initialize basic controller ands views to get a scaffold for logins/registers of users.
Maybe authentication? It will create some views and routes.
https://laravel.com/docs/5.2/authentication#authentication-quickstart
The command php artisan make:auth if you are using 5.2.*
no you don't if you want to create a controller just tphp artisan make:controller HomeController and a controller will be created for you :)

Categories