When trying to get records from a table I get this error:
Illuminate\Contracts\Container\BindingResolutionException Target class [App\Http\Controllers\Usuarios\UsuariosController] does not exist.
web.php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthControllers;
use App\Http\Controllers\Usuarios;
Route::get('ver-usuarios', [App\Http\Controllers\Usuarios\UsuariosController::class, 'index'])->name('ver-usuarios');
Controller
<?php
namespace App\Http\Controllers\Usuarios;
namespace App\Models;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class UsuariosController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$usuarios_activos = User::where('estado','ACTIVO')->get();
dd($usuarios_activos);
}
}
The error seems to start from the fact that you are declaring your UsersController controller class under the context of 2 namespaces.
So
App\Models
it's overriding aApp\Http\Controllers\Usuarios
and so when you try to use the class elsewhere it can't be located.I will exemplify the above in this way:
whose output will be:
Final comments:
namespace App\Models
from your controller your code should work.UsuariosController
either at the beginning with or when you use said class in the routeuse
get