The HomeController default on laravel doesn't exist - php

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 :)

Related

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

Laravel Controller not adding to route list

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

How to group Controller using route namespace Laravel

I am working on laravel project i have completed my admin panel and my all conrollers are in namespace App\Http\Controllers and everything is working perfectly fine now but i want to move all my Controller in folder AdminController for making everything more clear and smooth(Kind of HMVC technique).For this I add namespace on route which I did something like this
Route::group(['prefix' =>'admin','namespace'=>'AdminController'], function ()
{
/// all route
});
and i move all my conrollers in folder AdminController.Now its giving me error Cannot redeclare class Chemist\Http\Controllers\RoleController
Note: My baseconroller are in director App\Http\Controllers and all other controller are in App\Http\Controllers\AdminController
Create custom controller dir like
php artisan make:controller subDriectory/YourController
php artisan make:controller subDriectory/YourController --plain

How to rollback effects of php artisan make:auth in laravel 5

I am new to laravel.
I was in middle of my project. I googled for login validation in laravel 5.
I found this command
php artisan make:auth
it Created several classes and also modified my welcome.blade.php
there was several code in welcome.blade.php.
Now How to rollback effects of this command.
Please Help.
Look at the make:auth command source code to understand what exactly files this command added or changed and revert changed back.
manually you have to remove following files
auth/login.blade.php
auth/register.blade.php
auth/passwords/email.blade.php
auth/passwords/reset.blade.php
layouts/app.blade.php
home.blade.php
Go to routes/web.php, delete the created routes by the command make:auth. Remove these two lines and your project will work fine as before.
Auth::routes();
Route::get('/home', 'HomeController#index');
The answer is NO.
There is no way you can rollback make:auth command as yet in laravel..
You can remove auth manually be removing auth from app controller and and auth route. And if you were lucky enough to have welcome file opened in some IDE then there was a chance of ctrl+z bcause IDEs keep back in memory,., but other then that there is no way retrieving backup the data.
we can simply remove below line form wep.php routes folder.
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
you can also remove the view files: like auth folder ,app.blade.php, home.blade.php

Laravel 4 Routes Not Working

I did look at the other Laravel Route questions, but nothing seems to work for me.
I am trying Laravel 4. I ran the command:
php artisan controller:make PhotoController
to create my controller. Then I added a route in my routes.php file as such:
Route::resource('photo', 'PhotoController');
When I go to localhost/photo, I see 404 Not Found.
Any ideas? I can see the root and /index.php, they both say "Hello World", so I know something is working.
You might need to run
composer dumpautoload
from the command line, so laravel knows the controller is there.
you can also try this:
php artisan dump-autoload

Categories