How to troubleshoot the error: Reflectionexception (-1) Class App Http Controllers admin Ufcontroller does not exist

Asked

Viewed 1,274 times

2

Follow the code snippet route/web.php

//Gerenciar  UFs
$this->group(['middleware' => ['auth'], 'namespace' =>'admin','prefix'=>'ufs'], function(){
    //Inicio das Rotas de gerenciar os UFs
    $this->post('cadastro','UfController@cadastro')->name('uf.cadastro');
    $this->post('uf','UfController@consulta')->name('uf.consulta');
    $this->post('atualiza', 'UfController@atualiza')->name('uf.atualiza');
    $this->post('remove','UfController@remove')->name('uf.remove');
    $this->get('edita/{id}','UfController@edita')->name('uf.edita');
    $this->get('novo','UfController@novo')->name('uf.novo');
    $this->get('/uf','UfController@index')->name('admin.uf'); 
   //Final das Rotas de gerenciar os UFs
}); 

Follow the code Ufcontroller.php

namespace App\Http\Controllers\Admin;

use Illuminate\Support\Facades\DB;
use App\Models\UF;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UFController extends Controller
{
    private $uf;

    //Construtor do UF
    public function __construct(UF $uf)
    {
        $this->uf = $uf;
    }

    public function index()
    {
        $ufs =  UF::all();
        $permissao = verificarPermissao('UF');
        return view('admin.uf.index', ['ufs' => $ufs, 'permissoes' => $permissao]);
    }

    //Este método apresenta o formulário para cadastrar um novo UF
   public function novo()
   {
       return view('admin.uf.novo');
   }

   //Método para cadastrar um UF
   public function cadastro(Request $request)
    {
        $uf = new UF();
        $uf->uf_sigla = $request->get('sigla');
        $uf->uf_descricao = $request->get('descricao');
        $uf->ativo = $request->get('ativo');

        $response =  $uf->salvar($uf);  

            if($response['success']){
                return redirect()
                            ->route('admin.uf') 
                            ->with('success',$response['message']);
            }
            else{
                return redirect()
                            ->back()
                            ->with('error',$response['message']); 
            }   
    }

    //Método que redireciona para a página de atualizar o UF
    public function edita($id)
    {
        return view('admin.uf.edita', ['ufs' => UF::find($id)]);
    }

   //Este método remove a UF
   public function remove(Request $request)
   {
     $uf = UF::find($request->id);

      if (!$uf)
       return response()
                ->json(['error' => 'not_found'], 404);

      $response =  $uf->deletar($uf);  

      if($response['success'])
      {
       return response()
               ->json(['success' => $response['message']], 200);  

      }else
      {
            // Caso não delete, informa um erro inesperado
       return redirect()
                ->json(['error' => $response['message']], 500);        
      } 
   }

    //Método de consulta da UF
    public function consulta(Request $request)
    { 
        $condicoes = [];

        if($request->uf_sigla != null){
            $condicoes[] = [DB::raw('upper(uf_sigla)'), 'like', DB::raw('upper("%'.$request->get('uf_sigla').'%")')];
        }

        if($request->uf_descricao != null){
            $condicoes[] = [DB::raw('upper(uf_descricao)'), 'like', DB::raw('upper("%'.$request->get('uf_descricao').'%")')];
        }

        if($request->ativo != null){
           $condicoes[] = ['ativo', '=', $request->get('ativo')];

        }


      $request->flash(['uf_sigla','uf_descricao','ativo']);

      $ufs = UF::where($condicoes)->orderBy('uf_sigla')->get();
      $permissao = verificarPermissao('UF');

      return view('admin.uf.index', ['ufs' =>  $ufs, 'permissoes' => $permissao]);

    } 
      //Método para atualiza o uf
      public function atualiza(Request $request)
      {

        $uf= UF::find($request->get('id'));
        $uf->uf_sigla = $request->get('sigla');
        $uf->uf_descricao = $request->get('descricao');
        $uf->ativo = $request->get('ativo');


        $response =  $uf->alterar($uf);  

          if($response['success'])
          {
              return redirect()
                        ->route('admin.uf') 
                        ->with('success',$response['message']);
          }else
          {
              return redirect()
                        ->back()
                        ->with('error',$response['message']); 

          }

      }
}

inserir a descrição da imagem aqui

3 answers

0

Change that line. I think it’s case sensitive problems:

$this->group(['middleware' => ['auth'], 'namespace' =>'Admin','prefix'=>'ufs']

The namespace you put 'admin' and conveniently should be Admin..

Have to take care of it because in windows does not accuse error.

0


You created UFController and is calling UfController. See the F minuscule.

  • Change applied and successfully solved.

  • @Hugoleonardo if friend’s answer solved your problem mark it as accepted" Click this icon next to the arrows of his answer.

0

Suggested changes have been applied and solved.

$this->group(['middleware' => ['auth'], 'namespace' =>'Admin','prefix'=>'ufs']

$this->post('registration','Ufcontroller@registration')->name('Uf.registration');

Solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.