dimanche 18 août 2019

How to save random generated via controller

I have an api that will be used for submitting tickets via a mobile app . On my ticketController api its generating the ref when I do a post but its not saving the generated ref on the db.

When I do a dd, I can see the generated value , problem comes when its time to save.

Here is a snippet of the code that I am using to do the post

$data =  rand(10000, 999999999);

        $fault = Ticket::firstOrNew(['id' => $request->get('id')]);

        $fault->ref_no = $data;

        $ticket->service_id = $request->get('service_id');
        $ticket->ticket_subject_id = $request->get('ticket_subject_id');
        $ticket->description = $request->get('description');
        $ticket->user_id = $request->get('user_id');
        $ticket->company_id = $request->get('company_id');
        $ticket->full_name = $request->get('full_name');
        $ticket->phone = $request->get('phone');
        $ticket->address = $request->get('address');
        $ticket->city_id = $request->get('city_id');
        if ($request->file('photo')) {
            $ticket->photo = $this->upload($request->file('photo'), 'tickets')->getFileName();
        } else {
            $ticket->photo = $ticket->photo;
        }
        $ticket->latitude = $request->get('latitude');
        $ticket->longitude = $request->get('longitude');

        dd($ticket);

I want to be able to save all the data on the db including the ref_no.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Z6tVgH
via IFTTT

Aucun commentaire:

Enregistrer un commentaire