Laravel错误:参数1传递给App \ Services \ Booking \ BookingService :: save()必须是App \ Http \ Requests \的实例

How to fix the error:

Argument 1 passed to App\Services\Booking\BookingService::save() must be an instance of App\Http\Requests\StoreBookingRequestType, instance of Illuminate\Http\Request given, called in C:\xampp_n\htdocs\get-served-admin\app\Http\Controllers\BookingController.php on line 75.

I keep getting the error when I try to save a booking.

in the app\Services\Booking\BookingService.php

/**
     * Save Booking to database
     *
     * @param StoreBookingRequestType $request
     * @return string
     */
    public function save(StoreBookingRequestType $request)
    {
        DB::beginTransaction();

        try {

            $request['user'] = $request->get('user_id');

            Booking::create($request->all());

        } catch (\Exception $e) {

            DB::rollback();

            Log::error('Booking Error: Storing New Record - '.$e->getMessage());

            return BookingResponseType::ERROR;
        }

        DB::commit();

        return BookingResponseType::SUCCESS;
    }

in the controller app\Http\Controllers\BookingController.php

namespace App\Http\Controllers;

use App\Booking;
use App\Client;
use App\Enums\BookingResponseType;
use App\PaymentMethod;
use App\PaymentStatus;
use App\Services\Booking\BookingService;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class BookingController extends Controller{
    private $payment_methods;
    private $payment_statuses;
    private $clients;
    private $users;
    private $booking_service;
    private $booking_service;

    public function __construct()
    {
        view()->share('page_title','Bookings');

        $this->payment_methods  = PaymentMethod::all()->pluck('name','id');
        $this->payment_statuses = PaymentStatus::all()->pluck('name','id');
        $this->clients          = Client::all()->pluck('fullname','id');
        $this->users            = User::all()->pluck('fullname','id');

        $this->booking_service  = new BookingService();
    }


    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return BookingResponseType
     */
    public function store(Request $request)
    {
        DB::beginTransaction();

        try {

            $action = $this->booking_service->save($request);

            if($action=="Success") {
                flash('Record has been successfully saved.')->success();
            } else {
                flash('Error');
            }

        } catch (\Exception $e) {

            DB::rollback();

            flash('Error: '.$e->getMessage())->error();

            return redirect()->back()->withInput($request->all());
        }

        DB::commit();

        return redirect()->back();
    }
}
douken7402
douken7402 错误消息从字面上告诉您问题的答案,请习惯阅读并理解错误消息,因为他们将是您最好的朋友。
一年多之前 回复
duanlu1279
duanlu1279 您是否尝试在Store操作中使用StoreBookingRequestType作为参数类型?store(StoreBookingRequestType$request)
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问