显示常量表达式包含无效操作
当我试图传递它显示的函数值时,我是 laravel livewire 的新手
常量表达式包含无效操作。
我正在尝试这个功能
'suppliers_master_id' => $this->generateRegistrationId(),
我的代码
<?php
namespace App\Http\Livewire\Purchase;
use App\Supplier;
use Livewire\Component;
class AddSuppliers extends Component
{
public $form = [
'supplier' => '',
'email' => '',
'phone' => '',
'address' => '',
'city' => '',
'state' => '',
'pincode' => '',
'GSTIN' => '',
'suppliers_master_id' => $this->generateRegistrationId(),
];
public function submit()
{
$this->validate([
'form.supplier' => 'required|string|max:255',
'form.email' => 'required|email',
'form.phone' => 'required|string|max:10',
'form.address' => 'required|string|max:255',
'form.city' => 'required|string|max:255',
'form.state' => 'required|string|max:255',
'form.pincode' => 'required|string|max:6',
'form.GSTIN' => 'required|string|max:255',
]);
Supplier::create($this->form);
session()->flash('message', 'Supplier Added successfully .');
return redirect()->to('/addsuppliers');
}
function generateRegistrationId() {
$id = 'SIIT_' . mt_rand(1000000000, 9999999999); // better than rand()
// call the same function if the id exists already
if ($this->registrationIdExists($id)) {
return $this->generateRegistrationId();
}
// otherwise, it's valid and can be used
return $id;
}
function registrationIdExists($id) {
// query the database and return a boolean
// for instance, it might look like this in Laravel
return Supplier::where('suppliers_master_id', $id)->exists();
}
public function render()
{
return view('livewire.purchase.add-suppliers');
}
}