Laravel 6错误-Illuminate \ Contracts \ Container \ BindingResolutionException目标类不存在

时间:2020-06-08 11:18:35

标签: php laravel

我正在尝试将数据插入数据库中,但出现此错误:

Illuminate \ Contracts \ Container \ BindingResolutionException
目标类 [App \ Http \ Controllers \ Master \ Request]不存在。

尽管我的Vendor Model和VendorController在正确的目录中。

这是我的供应商模型源代码(\ app \ Model \ Master):

<?php

namespace App\Model\Master;

use Illuminate\Database\Eloquent\Model;

class Vendor extends Model
{
    protected $table = 'vendors';

    public function user_modify()
    {
        return $this->belongsTo('\App\User', 'user_modified');
    }
}

这是我的VendorController源代码(\ app \ Http \ Controllers \ Master):

<?php

namespace App\Http\Controllers\Master;

use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;

class VendorController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view("vendor.index");
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view("vendor.create");
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $data = new Vendor();

        $data->vendor_firstname = $request->first_name;
        $data->vendor_lastname = $request->last_name;
        $data->vendor_address = $request->address;
        $data->vendor_phone = $request->contact;
        $data->vendor_firstname = $request->first_name;
        $data->active = $request->vendor_status;
        $data->vendor_modified = Auth::user()->id;

        if($data->save()){
            return redirect()->route('vendor.index');
        }else{
            return redirect()->back();
        }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

这是我的路线列表:

enter image description here

什么原因导致此错误?以及我该如何解决?尝试运行php artisan config:cache和composer dump-autoload,但还是没有运气。

1 个答案:

答案 0 :(得分:2)

在您的控制器文件中添加use Illuminate\Http\Request;

<?php

namespace App\Http\Controllers\Master;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;

class VendorController extends Controller
{
    public function index()
    {
        return view("vendor.index");
    }
    public function create()
    {
        return view("vendor.create");
    }
    public function store(Request $request)
    {
        $data = new Vendor();

        $data->vendor_firstname = $request->first_name;
        $data->vendor_lastname = $request->last_name;
        $data->vendor_address = $request->address;
        $data->vendor_phone = $request->contact;
        $data->vendor_firstname = $request->first_name;
        $data->active = $request->vendor_status;
        $data->vendor_modified = Auth::user()->id;

        if($data->save()){
            return redirect()->route('vendor.index');
        }else{
            return redirect()->back();
        }
    }
}