Laravel 6 目标类 [App\Http\Controllers\Admin\Tracker] 不存在

Posted

技术标签:

【中文标题】Laravel 6 目标类 [App\\Http\\Controllers\\Admin\\Tracker] 不存在【英文标题】:Laravel 6 Target class [App\Http\Controllers\Admin\Tracker] does not existLaravel 6 目标类 [App\Http\Controllers\Admin\Tracker] 不存在 【发布时间】:2020-06-18 04:00:48 【问题描述】:

我正在尝试删除一条记录,但我收到这个类不存在的错误,我正在使用 Laravel 6,希望您的帮助或建议

我不知道命名空间是不是错了,虽然我已经检查过并且没问题,或者控制器中的东西

我已经查看了方法,但找不到解决方案 我附上我的驱动程序文件和我的路径

控制器

<?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);
        
    


路线

 Route::get('tracker/post/destroy', 'Admin\Tracker@confirmDestroy');
        Route::resource('tracker', 'Admin\TrackerController');

【问题讨论】:

稍微清理了一下,但您应该考虑发布确切的错误。有关详细信息,请参阅minimal reproducible example 页面。 【参考方案1】:

我想你在一个组里,把这条路线:

Route::get('tracker/post/destroy', 'Admin\Tracker@confirmDestroy');

你忘记了控制器后缀:

Route::get('tracker/post/destroy', 'Admin\TrackerController@confirmDestroy');

【讨论】:

一个评论就足够了。然而,你在 TrackerController 中多了一个l

以上是关于Laravel 6 目标类 [App\Http\Controllers\Admin\Tracker] 不存在的主要内容,如果未能解决你的问题,请参考以下文章

目标类 [UserController] 不存在 Laravel 8

Laravel 8:目标类不存在[重复]

Laravel 绑定解析异常。目标类不存在[重复]

目标类控制器不存在 - Laravel 8

Laravel,该类存在,但我得到目标类 [PagesController] 不存在

Laravel 包开发 - 目标类 [ControllerName] 不存在