Добрый день.
Миграция
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->bigIncrements('id')->unsigned();
$table->tinyInteger('category_id')->unsigned();
$table->tinyInteger('brand_id')->unsigned();
$table->string('title',255)->unique();
$table->string('alias',255)->nullable();
$table->text('content')->nullable();
$table->float('price')->default(0);
$table->float('old_price')->default(0)->nullable();
$table->enum('status',['0','1'])->default(1);
$table->string('keywords',255)->default(NULL)->nullable();
$table->string('description',255)->default(NULL)->nullable();
$table->json('gallery',255)->default(NULL)->nullable();
$table->string('img',255)->nullable();
$table->enum('hit',['0','1'])->default(0)->index();
$table->json('related')->default(NULL)->nullable();
$table->timestamps();
$table->softDeletes();
$table->index(['category_id','brand_id']);
});
}
Контроллер
public function update(UpdateProductRequest $request, $id)
{
$attributes = json_decode($request['attributes']);
$product = Product::findOrFail($id);
$product->update($request->required());
$product->attributes()->sync($attributes);
return new ProductResource($product);
}
И сам request
public function rules()
{
return [
'category_id' => 'required|exists:categories,id',
'brand_id' => 'nullable',
'title' => [
'required',
Rule::unique('products')->ignore($this->product)
],
'content' => 'required|string',
'price' => 'required|numeric',
'old_price' => 'nullable|numeric',
'status' => 'required',
'description' => 'nullable|string',
'img' => 'nullable|string',
'gallery' => 'nullable',
'hit' => 'nullable',
'related' => 'nullable',
];
}
Laravel 7
И ошибка
{message: "Method App\Http\Requests\UpdateProductRequest::required does not exist.",…}
exception: "BadMethodCallException"
file: "/var/www/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php"
line: 103
message: "Method App\\Http\\Requests\\UpdateProductRequest::required does not exist."
trace: [{file: "/var/www/app/Http/Controllers/Admin/ProductController.php", line: 85, function: "__call",…},…]