POST http:// localhost:8888 / clientquote-app / backend / api / createQuote 500(内部服务器错误)

时间:2019-09-18 15:21:11

标签: angular laravel

我正在开发客户端门户应用程序。 Laravel-5.8是后端,而Angular-7是前端。 我正在使用POST REQUEST。

客户注册后,会向该客户发送一封电子邮件,以成功注册。

ApiController

public function mailSend($mainData) {
    $data = array();
    $data = array('content' => $mainData['content']);
    //print_r($mainData);exit;
    Mail::send(['text' => 'test'], $data, function($message) use ($mainData) {
        $message->to($mainData['to'])->subject
                ($mainData['subject']);
        $message->from($mainData['from']);
    });
}


public function createClientQuote(Request $request) {
$validator = Validator::make($request->all(), [
                'first_name' => 'required',
                'last_name' => 'required',
                'email' => 'required|email',
                'phone' => 'required|max14',
                'business_name' => 'required',
                'truck_type' => 'required',
                'truck_required' => 'required',
                'quote_origin' => 'required',
                'quote_destination' => 'required',
                'commodity' => 'required',  
                'loading_date' => 'required',                                     
    ]);
    if ($validator->fails()) {
        return $this->returnResponse(false, ['error' => $validator->errors()], 1, 'Invalid Quote Data');
    }
    $input = $request->all();

   // $success = array();
    $clientquote = new ClientQuote;

    $clientquote->first_name = $input['first_name'];
    $clientquote->last_name = $input['last_name'];
    $clientquote->email = $input['email'];
    $clientquote->phone = $input['phone'];
    $clientquote->business_name = $input['business_name'];
    $clientquote->truck_required = $input['truck_type'];
    $clientquote->quote_origin = $input['quote_origin'];
    $clientquote->quote_destination = $input['quote_destination'];
    $clientquote->commodity = $input['commodity'];
    // $clientquote->weight = $input['weight'];
    $clientquote->loading_date = $input['loading_date'];
    $clientquote->save();

        $mainData = array();
        $mainData['to'] = $clientquote->toArray()['email'];
        $mainData['from'] = "support@tsllimited.com";
        $mainData['subject'] = "Client Quote";
        $mainData['content'] = "Your Quote have been successfully received. You will hear from us shortly through the provided email. Thank you!";

        $this->mailSend($mainData);

    $success = array();
    $success['clientquote']=$clientquote;


    return $this->returnResponse(true, $success, 0, 'Client Quote added successfully.');
}  

资源->视图-> tests.blade.php

<?php 
echo $content; 
?>

api.php

Route::post('createClientQuote','ApiController@createClientQuote');

当我从前端单击“提交”按钮时,在控制台中出现此错误:

error1

然后,当我单击错误时,它将我重定向到另一个错误页面:

error2

我观察到错误来自后端。我仔细检查了一下,但找不到源。我确定这是一个发帖请求。我该如何解决?

0 个答案:

没有答案