Laravel can not find the driver in App \ Http \ Controllers

2

I am creating a project in laravel, I have created a driver, and when I try to link it to the path, it throws me an error that does not find it. I show you the code    CONTROLLER: Home     

namespace App\Http\Controllers\Home;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Http\Request;

class Home extends Controller
{
 public function base();       //controlador home
  {
   return view('index');
   }
 }

WEB APP

Route::get('/','Home.php@base');
    
asked by FGB 05.04.2018 в 18:46
source

3 answers

1

The drivers in Laravel are invoked and created as follows:

Route::get('/about', 'HomeController@index');
  

As you can see, the controller must have the syntax of the first   singular word followed immediately by the word controller,   Check that each word starts with a capital letter; likewise I tell you that no   requires php extension, modify it as I told you and you should   to work

EXAMPLES

// Right

Route::get('/about', 'HomeController@index'); 

// incorrect

Route::get('/about', 'Home.php@index'); 
    
answered by 05.04.2018 / 18:51
source
3

The error is in how you define the route, and maybe how you are defining the namespace, since you usually have to include the name of the controller and its method, separated by an @:

Route::get('/','HomeController@base');

The other thing that I see in your namespace is that the file name of the controller (or class) should not be included, and it is good practice that the file and the name of the class include the word 'controller ':

app / Http / Controllers / HomeController.php

namespace App\Http\Controllers;

class HomeController extends Controller
{
    public function base()
    {
        return view('index');
    }
}

Keep in mind that the controller (Controller) you wish to extend is located in the namespace App \ Http \ Controllers.

Finally, in this particular case you could ignore the controller method, because you simply want to show a view, and you could do it directly from the route definition, using Route::view() :

Route::view('/', 'index');

More information in the documentation:

link

    
answered by 05.04.2018 в 18:54
0

Since your controller is called only Home you could try this:

Route::get('/','Home@base');

although the correct thing is that the name of the controller is HomeController to be able to call it. Execute with your project: php artisan make:controller HomeController to create a new controller, there copies your function base and in your routes you call it the right way

Route::get('/','HomeController@base');
    
answered by 05.04.2018 в 19:35