0

I have been trying to insert data using query into two columns of a table but there's something missing that its not sending data in the other column named booking_code.
It is inserting the booking_id into the table but not booking_code.

Here is the controller:

public function store(CreatePaymentRequest $request)
    {
        $input = $request->all();

        $booking_id = $request->booking_id;
        $booking_code = Booking::find($booking_id)->booking_code;
        $this['booking_code'] = $booking_code;

        $payment = $this->paymentRepository->create($input);

        Flash::success('Payment saved successfully.');

        return redirect(route('admin.payments.index'));
    }
Shoaib Akhtar
  • 85
  • 1
  • 1
  • 9

1 Answers1

0

Please have a look at the Relevant Documentation Pages

You may also use the create method to save a new model in a single line. The inserted model instance will be returned to you from the method. However, before doing so, you will need to specify either a fillable or guarded attribute on the model, as all Eloquent models protect against mass-assignment by default.

That means that you have to set, in Model, which fields you will allow to be "mass-assigned".

In your case, it will looks something like

class Booking extends Model 
(...)
{
   protected $fillable = ['booking_code', (...)];
}
(...)

In the code you provided though, I can't see how you build an $input variable so maybe the issue is there? Maybe it's just some typo.

matiit
  • 7,969
  • 5
  • 41
  • 65