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

5
  • Does this answer your question? Target class controller does not exist - Laravel 8 Commented Sep 26, 2020 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 Commented Sep 26, 2020 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 stackoverflow.com/questions/64037500/… Commented Sep 26, 2020 at 18:53
  • Try composer dump-autoload Commented Sep 26, 2020 at 19:00
  • That would be use App\Http\Controllers\SaludarController;? Also try with regenerate all classes composer dump-autoload Commented Sep 26, 2020 at 19:03

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

6 Comments

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 <stackoverflow.com/questions/57545668/…>
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
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.
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.
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
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.