У меня проблема, что customer_id имеет значение null, если в таблице нет данных. Я знаю, что есть функция IFNULL, с помощью которой я могу изменить значение customer_id на ноль на 0. Итак, мой запрос не работает. проверил много связанных с этим проблем, решенных в потоке укладки, но я не смог найти solutino для себя, если кто-то может помочь мне с ним, будет любезно с его стороны. он показывает мне эту ошибку
«сообщение»: «Попытка получить свойство необъекта»,
Код customerController равен
public function store(Request $request)
{
//
try {
$this->validate($request,[
'name'=>'required',
'contact'=>'required|unique:Customers',
// 'contact'=>'required',
'address'=>'required',
'email'=>'required|string|email|max:191|unique:Customers',
]);
$getId = DB::table('Customers')->select('*', DB::raw('ifnull(id,0)'))->first();
$getfirst = $getId->id;
if($getfirst == 0)
{
$getfirst = 1;
$incId = $getfirst;
}
else{
$incId = $getfirst+1;
}
// $lastInsertedId= $Customer->id;
$Customer= Customer::create([
'name'=>$request['name']."-". $incId ,
'contact'=>$request['contact'],
'address'=>$request['address'],
'email'=>$request['email']
]);
return response()->json($Customer);
}
catch (Exception $e) {
return response()->json($e->getMessage(), 500);
}
}
таблица клиентов:
public function up()
{
Schema::create('customers', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->default("مشتری");
$table->integer('contact')->unique();
$table->string('address');
$table->string('email')->unique();
$table->softDeletes();
$table->timestamps();
});
}