красноречивый метод создания подсветки не работает - PullRequest
0 голосов
/ 26 октября 2018

По какой-то причине я не могу создавать модели на этой странице.Это всегда работало до сегодняшнего дня.

Что я сделал

  1. Я смотрел на var_dump после и до OrderDetails::create(), и оба значения одинаковы.
  2. Я запутался с $fillable, и стало ясно, что когда имя столбца внутри заполняемого не совпадает с столбцом базы данных.Ошибка будет показана.
  3. Я перепробовал все варианты метода create, но все равно не повезло.

Я абсолютно не понимаю, что я здесь сделал неправильно.

дополнительная информация:

  1. Я перепутал с phpMailer, прежде чем обнаружил эту ошибку.Одна важная вещь, которую я сделал, это включила «разрешить менее безопасный доступ» (не точное слово), который конвертирует из «ssl» в «tls».

Ниже приведена одна из моделей, которые я не могу создать.Я решил показать часть кода, которая наиболее соответствует моей проблеме.

foreach($_SESSION['user_cart'] as $cart_items){

                $productId = $cart_items['product_id'];

            //quantity of items in the cart NOT quatity of item availble in the shop
                $quantity = $cart_items['quantity'];

                $item = Product::where('id', $productId)->first();

            //if for some reason, no matching id can be found. skip the item to avoid problems
                if(!$item) {continue;}
            //totalPrice of selected item * quantity in the cart
                $totalPrice = $item->price * $quantity;
                $totalPrice = number_format($totalPrice, 2 );

                // var_dump($order_id); //?????????????????????????????????????????????????????????????

                OrderDetail::create([
                    'user_id' => _user()->id,
                    'product_id' => $productId,
                    'unit_price' => $item->price,
                    'quantity' => $quantity,
                    'total' => $totalPrice,
                    'status' => 'Pending',
                    'order_no' => $order_id
                ]);
                $item->quantity = $item->quantity - $quantity;
                $item->save();

                // $test = OrderDetail::where("order_no", $order_id)->get();
                // var_dump($test[0]->order_no); //?????????????????????????????????????????????????????

                array_push($result['product'], [
                    'name' => $item->name,
                    'price' => $item->price,
                    'total' => $totalPrice,
                    'quantity' => $

Это моя модель OrderDetail

namespace SAM\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class OrderDetail extends Model
{
    //Illuminate setup6
    use SoftDeletes;
    public $timestamps = true;
    // vars to be inserted to
    protected $fillable = ['user_id', 'product_id', 'unit-price', 'quantity', 'total', 'status', 'order_no'];
    // protected $fillable = ['user_id', 'product_id', 'unit-price', 'quantity', 'total', 'statu_no'];
    protected $dates = ['deleted_at'];
}
...