MarlonV
215
2
Laravel

Storing data

Posted 2 months ago by MarlonV

Hey guys,

is it possible to save a value of a non existing field using this kind of store method? I want to add a barcode ($number) to it.

public function store(Request $request)
        {
              $validatedData = $request->validate([
                'first_name' => 'required|max:255',
                'last_name' => 'required|max:255',

             ]);

            $event = auth()->user()->events()->create($validatedData);

        
            return redirect()->route('/')->with('success', 'success');
        }
function generateBarcodeNumber() {
    $number = mt_rand(1000000000, 9999999999);

    if (barcodeNumberExists($number)) {
        return generateBarcodeNumber();
    }

    return $number;
}

function barcodeNumberExists($number) {

    return Event::whereBarcodeNumber($number)->exists();
}

Please sign in or create an account to participate in this conversation.