Здравствуйте, при создании товара появилась ошибка
"SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'on' for column `laravel-react`.`products`.`is_reccomended` at row 1 (SQL: insert into `products` (`title`, `slug`, `excerpt`, `content`, `descrtitle`, `descrtext`, `descr`, `regular_price`, `discount`, `currency`, `product_description_tab_content`, `product_ingredients_tab_content`, `product_usage_tab_content`, `is_reccomended`, `updated_at`, `created_at`) values (aaaa, aaaa, aaaa, aaaaaa, aaaa, aaaa, aaaaa, 11, 10, грн, , , , on, 2019-06-19 18:57:05, 2019-06-19 18:57:05))
app/Products.php
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Products extends Authenticatable
{
use Notifiable;
public $timestamps = true;
protected $table = 'products';
protected $primaryKey = 'id';
protected $fillable = [
'id',
'title',
'slug',
'excerpt',
'content',
'descrtitle',
'descrtext',
'descr',
'regular_price',
'sale_price',
'discount',
'currency',
'image',
'is_reccomended',
'product_description_tab_content',
'product_ingredients_tab_content',
'product_usage_tab_content',
'tab_bg',
];
protected $guarded = [];
protected $dates = [
'created_at',
'updated_at',
];
}
app/Http/Controllers/Admin/ProductsController.php
<?php
namespace App\Http\Controllers\Admin;
use App\Currencies;
use App\Helpers\GetArrayOf;
use App\Http\Requests\ProductsRequest;
use Validator;
use App\Products;
use App\Categories;
use App\CategoriesRelationship;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Helpers\ImageDNK;
class ProductsController extends Controller
{
public function addRequestProduct(ProductsRequest $request){
$validated = $request->validated();
$objProduct = new Products();
$objProduct = $objProduct->create($validated, [
'is_reccomended' => false,
'image' => ImageDNK::save($request, 'image'),
'tab_bg' => ImageDNK::save($request, 'tab_bg'),
]);
dd($objProduct);
if(!$objProduct){
return back()->with('error', 'Товар не создан. Попробуйте ещё раз');
}
$hasCategory = $request->input('product_category') != 0;
if($hasCategory){
$objCatsRels = new CategoriesRelationship();
$objCatsRels = $objCatsRels->create([
'object_id' => $objProduct->id,
'category_id' => $request->input('product_category'),
]);
}
if($objProduct && (!$hasCategory || $objCatsRels)){
return redirect(route('admin.products.edit', ['id' => $objProduct->id]))->with('success', trans('messages.products.successCreated'));
}
return back();
}
public function editRequestProduct(ProductsRequest $request, int $id){
$validated = $request->validated();
$objProducts = Products::find($id);
if(!$objProducts){
return abort('404');
}
$validated['image'] = ImageDNK::save($request, 'image');
$validated['tab_bg'] = ImageDNK::save($request, 'tab_bg');
$validated['is_reccomended'] = $request->has('is_reccomended') ? true : false;
$objProducts->fill($validated);
if(!$objProducts->save()){
return back()->with('error', 'Товар не изменен. Попробуйте ещё раз');
}
$hasCategory = $request->input('product_category') != 0;
if($hasCategory){
$objCatsRels = new CategoriesRelationship();
$objCatsRels = $objCatsRels->create([
'object_id' => $id,
'category_id' => $request->input('product_category'),
]);
}
if($objProducts && (!$hasCategory || $objCatsRels)){
return back()->with('success', trans('messages.products.successUpdated'));
}
return back()->with('error', 'Товар не изменен. Попробуйте ещё раз');
}
}
При этом редактирование проходит без ошибок.
Где искать ошибку?
Спасибо.