Ad

Laravel 6 Target Class [App\Http\Controllers\Admin\Tracker] Does Not Exist

- 1 answer

I am trying to delete a record but I get this error that this class does not exist, I am using Laravel 6, I hope your help or advice

I don't know if the namespace is wrong although I have checked and it is ok, or something in the controller

I have reviewed the methods and cannot find a solution I attach my driver file and my path

Controller

<?php

namespace App\Http\Controllers\Admin;

use App\Events\InstanceCreated;
use App\Pesvial\City;
use App\Pesvial\Instance;
use App\Pesvial\Tracker;
use App\Pesvial\TrackingServer;
use Illuminate\Http\Request;
use App\Pesvial\Vehicle;
use App\Http\Controllers\Controller;
use Auth;

class TrackerController extends Controller
{
    public function __construct( )
    {
        $this->uri = 'tracker';
        $this->perm = str_replace('_', '.', $this->uri);
        //$subdomain = \Route::current()->parameter('subdomain');
        $this->middleware('permission:'. $this->perm .'.create', ['only' => ['create', 'store']]);
        $this->middleware('permission:'. $this->perm .'.create', ['only' => ['create', 'store']]);
        $this->middleware('permission:'. $this->perm .'.read', ['only' => ['show']]);
        $this->middleware('permission:'. $this->perm .'.update', ['only' => ['edit', 'update','activate', 'confirmActivate']]);
        $this->middleware('permission:'. $this->perm .'.delete', ['only' => ['destroy', 'confirmDestroy']]);
        $this->middleware("one.permission:{$this->perm}.create&{$this->perm}.read&{$this->perm}.update&{$this->perm}.delete",
            ['only' => ['index']]);
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $q = null;
        $uri = $this->uri;
        $user = Auth::user();
        $perm = $this->perm;
        $title = trans_choice('app.' . $uri . '.title', 2);

        $items = Tracker::orderBy('purchased_at', 'desc');

        if($request->has('q')){
            $q = $request->input('q');
            $items->where('id', 'like', "%$q%");
        }

        $items = $items->paginate(20);


        // Show the page
        return view('chameleon.admin.'. $this->uri .'.index', compact('items', 'user', 'uri','q','perm','title'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $uri = $this->uri;
        $tracking_servers = TrackingServer::orderBy('name','asc')->get();
        return view('chameleon.admin.'. $this->uri .'.create_edit', compact('uri', 'max_file_size', 'terms','title', 'instances', 'cities','tracking_servers'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $rules = [
            'unique_id'   => 'required|unique:trackers,id',
            'tracking_server'   => 'required',
            'purchased_at' => 'nullable|date_format:Y-m-d',
        ];

        $this->validate($request, $rules);

        $item = new Tracker;
        $item->id = $request->input('unique_id');
        $item->serial = $request->input('serial');
        $item->purchased_at = $request->input('purchased_at');
        $item->password = $request->input('password', null);
        $item->invoice = $request->input('invoice', null);
        $item->brand = $request->input('brand', null);
        $item->model = $request->input('model', null);
        $item->observations = $request->input('comments');
        $item->state = $request->input('state');
        $item->tracking_server_id = $request->input('tracking_server', null);

        if ($item->save())
        {
            if (!$request->has('already_exists'))
            {

            }
        return redirect('/admin/'. $this->uri)->with('success', trans('app.' . $this->uri . '.store_success', ['name' => $item->name]));
        }
        return redirect('/admin/'. $this->uri)->with('error', trans('app.' . $this->uri . '.store_fail'));
    }


    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        return redirect('/admin/' . $this->uri);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $item = Tracker::findOrFail($id);
        $uri = $this->uri;
        $tracking_servers = TrackingServer::orderBy('name', 'asc')->get();
        return view('chameleon.admin.'. $this->uri .'.create_edit', compact('item','uri', 'tracking_servers'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $rules = [
            'unique_id'   => 'required|unique:trackers,id',
            'tracking_server'   => 'required',
            'purchased_at' => 'nullable|date_format:Y-m-d',
        ];

        $this->validate($request, $rules);

        $item = new Tracker;
        $item->id = $request->input('unique_id');
        $item->serial = $request->input('serial');
        $item->purchased_at = $request->input('purchased_at');
        $item->password = $request->input('password', null);
        $item->invoice = $request->input('invoice', null);
        $item->brand = $request->input('brand', null);
        $item->model = $request->input('model', null);
        $item->observations = $request->input('comments');
        $item->state = $request->input('state');
        $item->tracking_server_id = $request->input('tracking_server', null);

        if ($item->save())
        {
            return redirect('/admin/'. $this->uri)->with('success', trans('app.' . $this->uri . '.store_success', ['name' => $item->name]));
        }
        return redirect('/admin/'. $this->uri)->with('error', trans('app.' . $this->uri . '.store_fail'));

    }

    public function confirmDestroy($id)
    {
        $item = Tracker::findOrFail($id);
        $uri = $this->uri;
        $title = __("app.{$uri}.destroy");
        $page = session('cur_page');
        if(!$page){
            $page = 1;
        }
        return view("chameleon.admin.{$this->uri }.destroy", compact('item', 'uri', 'title', 'page'));
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $item = Tracker::findorFail($id);
            if($item->delete())
            {
            return redirect('/admin/'. $this->uri)->with('success', trans('app.' . $this->uri . '.destroy_success'));
        }
        return redirect('/admin/'. $this->uri)->with('error', trans('app.' . $this->uri . '.destroy_fail'));
    }
    public function itemsList()
    {
        $res = Tracker::get();
        $ret = [];
        if($res->count() > 0)
        {
            foreach ($res as $key => $value) {
                $ret[$key]['id'] = $value->id;
            }
        }
        return response()->json($ret);
    }

    public function map($subdomain)
    {
        $instance = Instance::where('subdomain', $subdomain)->first();
        if(!$instance)
        {
            abort(404);
        }
        $server = $instance->trackingServer;
        return view('instances.'. $this->uri .'.map', compact('item', 'uri', 'instance', 'server'));
    }
    public function trackersList()
    {
        $res = Tracker::orderBy('id', 'asc')->get();
        $ret = [];
        if($res->count() > 0)
        {
            foreach ($res as $key => $value) {
                $ret[$key]['id'] = $value->id;
                $ret[$key]['name'] = $value->id ;
            }
        }
        return response()->json($ret);
    }

    public function find(Request $request, $q)
    {
        if($request->ajax()){
            //$items = Tracker::availableTrackers($q);
            $items = Tracker::where('id', 'like', "%$q%")->get();
            $ret = [];
            foreach ($items as $key => $value) {
                $name = $value['id'];
                if($value['brand']){
                    $name .= " " . $value['brand'];
                }

                if($value['model']){
                    $name .= " " . $value['model'];
                }
                $ret[$key]['id'] = $value['id'];
                $ret[$key]['name'] = $name ;
                $ret[$key]['password'] = Helper::trackerPassword($value['id']);
            }
            return response()->json($ret);
        }
    }

    public function availableTrackersList(){
        $trackers = Tracker::availableTrackers();
        //print_r($trackers);
        $ret = [];
        foreach ($trackers as $key => $tracker){
            $ret[$key]['id'] = $tracker['id'];
            $ret[$key]['name'] = $tracker['id'];
        }
        return response()->json($ret);
    }

    public function dataTable(Request $request)
    {
        if($request->ajax()){

            $items = Tracker::orderBy("id", "asc")->get();

            $ret = [];
            foreach ($items as $key => $item) {
                $vehicle = $item->vehicle()->orderBy('start_at', 'desc')->first();
                $server = $item->trackingServer;

                array_push($ret, [
                    'imei' => $item->id,
                    'server' => $server ? $server->name : 'ND',
                    'vehicle' => $vehicle ? $vehicle->plate : "No asignado",
                    'from' => $vehicle ? $vehicle->pivot->start_at : '',
                    'to' => $vehicle && $vehicle->pivot->finish_at ? $vehicle->pivot->finish_at : 'Indefinido',
                    'replaced' => $vehicle && $vehicle->pivot->finished_at ? $vehicle->pivot->finished_at : '',
                    'fimei' => $item->id,
                ]);

            }
            return response()->json($ret);
        }
    }
}

Routes

 Route::get('tracker/{post}/destroy', 'Admin\[email protected]');
        Route::resource('tracker', 'Admin\TrackerController');
Ad

Answer

I suppose you are in a group, put in this route :

Route::get('tracker/{post}/destroy', 'Admin\[email protected]');

You forgot Controller suffix :

Route::get('tracker/{post}/destroy', 'Admin\[email protected]troy');
Ad
source: stackoverflow.com
Ad