Ad

Copying Fields Within The Same Model - OctoberCMS

- 1 answer

Morning all,

I am trying to create a button that will copy the organisation address and populate the organisation billing address fields. I have no idea where to start.

The fields in question are:

// I want to copy these values
$organisation->email = Input::get('email');
$organisation->line_1 = Input::get('line_1');
$organisation->line_2 = Input::get('line_2');
$organisation->line_3 = Input::get('line_3');
$organisation->city = Input::get('city');
$organisation->state = Input::get('state');
$organisation->postcode = Input::get('postcode');
$organisation->country = Input::get('country');

// To these fields
$organisation->billing_line_1 = Input::get('billing_line_1');
$organisation->billing_line_2 = Input::get('billing_line_2');
$organisation->billing_line_3 = Input::get('billing_line_3');
$organisation->billing_city = Input::get('billing_city');
$organisation->billing_state = Input::get('billing_state');
$organisation->billing_postcode = Input::get('billing_postcode');
$organisation->billing_country = Input::get('billing_country');

Here is the start of my function

// Copy Address Button

    public function onCopyAddress()
    {
        $organisation = Organisation::find($this->param('id'));

        // Copy address logic here
        
        $organisation->save();

        Flash::success($organisation->name." Address has been successfully copied.");

        return Redirect::to('/organisations/'.$organisation->id);

    }
Ad

Answer

This is the solution I came up with.

public function onCopyAddress()
{
    $organisation = Organisation::find($this->param('id'));

    $organisation->billing_line_1 = Input::get('line_1');
    $organisation->billing_line_2 = Input::get('line_2');
    $organisation->billing_line_3 = Input::get('line_3');
    $organisation->billing_city = Input::get('city');
    $organisation->billing_state = Input::get('state');
    $organisation->billing_postcode = Input::get('postcode');
    $organisation->billing_country = Input::get('country');

    $organisation->save();

    Flash::success($organisation->name." Address has been successfully copied.");

    return Redirect::to('/organisations/'.$organisation->id);

}
Ad
source: stackoverflow.com
Ad