0

everyone! I tried everything and there is no way to fix this problem

laravel version 8.6.0

enter image description here

SalaudarController.php

<?php

namespace Blog\Http\Controllers;

use Illuminate\Http\Request;

class SaludarController extends Controller
{
    public function decirHola($persona= 'humano')(
      return "hola" . $persona . "<br /> <a href='"
      .route('decir.bienvenido', ["blogger" => $persona]).
      "'>Decir Bienvenido </a> ";
      )
}

web.php

<?php

use Illuminate\Support\Facades\Route;
use Blog\app\Http\Controllers;

Route::get('/hola/{persona?}', [SaludarController::class, 'decirHola']);

I read the other threads of this same question, I applied all the suggestions but the problem persists. I read your suggestions

jmontegrosso
  • 89
  • 1
  • 11
  • Does this answer your question? [Target class controller does not exist - Laravel 8](https://stackoverflow.com/questions/63807930/target-class-controller-does-not-exist-laravel-8) – Wesley Smith Sep 26 '20 at 18:45
  • Your `SalaudarController.php` controller's namespace should probably be `namespace App\Http\Controllers;`, at least according to convention (though you could use what you have if you really wanted to, but I wouldnt). In any event, see the question marked with the duplicate tag above for how to properly set up your routes to use your controller's namespace – Wesley Smith Sep 26 '20 at 18:48
  • Please let us know if you have any issue implementing that namespace change and the solution for configuring the route, see also this duplicate question https://stackoverflow.com/questions/64037500/defining-a-namespace-for-laravel-8-routes/64037683#64037683 – Wesley Smith Sep 26 '20 at 18:53
  • Try `composer dump-autoload` – STA Sep 26 '20 at 19:00
  • That would be `use App\Http\Controllers\SaludarController;`? Also try with regenerate all classes `composer dump-autoload` – STA Sep 26 '20 at 19:03

1 Answers1

0

Try importing Blog\Http\Controllers\SaludarController rather than Blog\app\Http\Controllers.

You don't need to include the app directory in your namespace as it's already registered as a composer autoload path (see https://github.com/laravel/laravel/blob/master/composer.json).

Paul Adams
  • 11
  • 1
  • By the way, the default Laravel namespace is `App`, so if you want to use `Blog` instead, you'll need to run `php artisan app:namespace Blog`. See – Paul Adams Sep 26 '20 at 18:34
  • This is incorrect. Per convention and PSR 4, if the controller is in the `app/http/controllers` folder (which is what the image shows) the correct namespace would be `namespace App\Http\Controllers;` The namespace should be corrected, as well as the import statement – Wesley Smith Sep 26 '20 at 18:50
  • It depends what his app namespace is. Since he used `Blog\Http\Controllers` in `SalaudarController`, I guessed he'd changed the default namespace to `Blog` using the `php artisan app:name` command. It seems that command was removed though in Laravel 6. – Paul Adams Sep 26 '20 at 18:54
  • For what its worth though, there is a better way to fix the actual issue (regardless of the namespace used). ie by configuring the `RouteServiceProvider` to use the applications namespace. – Wesley Smith Sep 26 '20 at 18:58
  • In fairness though, if you add something like "If you've changed your applications namespace to `Blog` rather than the default `App` via something like `php artisan app:namespace Blog` then try ....." I will remove my downvote. It would be a reasonable answer with that small caveat :) – Wesley Smith Sep 26 '20 at 19:01
  • 1
    I changed the namespace of my project to blog in cmd. I already discovered the problem. public function decirHola($persona= 'humano') { there is a brace, instead of the parenthesis – jmontegrosso Sep 26 '20 at 19:25