laravel-admin模型表单关联关系处理

laravel-admin模型表单的关联关系处理不支持小驼峰写法
用商品的规格举例
商品模型Goods.php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Goods extends Model
{

    protected $table = 'goods';
    //这里不能用小驼峰goodsSkus,否则关联关系处理会失效
    public function skus()
    {
        return $this->hasMany(GoodsSku::class, 'goods_id');
    }
}

商品规格模型GoodsSku.php



namespace App\Models;

use App\Exceptions\InternalException;
use Illuminate\Database\Eloquent\Model;

class GoodsSku extends Model
{
    protected $table = 'goods_skus';
}

GoodsController.php

//用skus可以如果用goodsSkus就会失效
$form->hasMany('skus', __('Goods Sku'), function (Form\NestedForm $form) {
    $form->text('title', __('Sku Name'))->rules('required');
    $form->text('description', __('Sku Description'))->rules('required');
    $form->text('price', __('Price'))->rules('required|numeric|min:0.01');
    $form->text('stock', __('Stock'))->rules('required|integer|min:0');
});

你可能感兴趣的:(laravel-admin,laravel,php)