samedi 18 novembre 2017

Laravel Backpack - Set extra attributes before page save

In my PageTemplates.php I have a field like this:

$this->crud->addField([
    'name' => 'adres',
    'label' => 'Adres',
    'type' => 'address',
    'fake' => true,
]);

Now I would like to save also the latitude and longitude of the address they give in (if it can be found). I've copied the PageCrudController and changed the config in config/backpack/pagemanager.php to:

return [
    'admin_controller_class' => 'App\Http\Controllers\Admin\PageCrudController',
    'page_model_class'       => 'App\Models\Page',
];

In my store function I have:

public function store(StoreRequest $request)
{
    $address = $request->request->get('adres');
    $addressObj = app('geocoder')->geocode($address)->get()->first();

    if($addressObj)
    {

    }

    $this->addDefaultPageFields(\Request::input('template'));
    $this->useTemplate(\Request::input('template'));

    return parent::storeCrud();
}

But what do I place in the if statement? How can I add (= set) an extra field to the extras field in my database?



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

Aucun commentaire:

Enregistrer un commentaire