Friday 15 February 2013

php - Laravel: Extend models from a second Laravel application -



php - Laravel: Extend models from a second Laravel application -

i wrote rest api laravel. on top of want create admin panel lot of statistics , "mighty" moderation tools should render on server-side. while rest api uses oauth2.0 , returns json+hal (hateoas), admin panel utilize http basic auth plus normal credential login session based authentication.

i know possible utilize sec auth-filter , route groups create happening in 1 application. , know libs loaded if needed. want create sec application independent.

why? maintain rest api lightweight: no unnecessary libraries, no sec auth-layer, no additional routes, rules , filters, etc. rest api restful , not want add together additional clutter. though might create testing little bit more complicated.

here how should like:

backend

rest (laravel application 1)

-- app

--- models

---- restapimodel.php

admin (laravel application 2)

-- app

--- models

---- adminmodel.php

the problem is: in application 2 need work models of application 1 s.th. like

class adminmodel extends restapimodel { protected $connection = 'application_1_database'; // statistical methods // database manipulation // etc. }

i have 2 questions:

how can create possible? "adminmodel extends restapimodel" won't work. have utilize namespaces, traits or include model on top of file? how solve this?

what think finish approach separate api , administration?

thanks in advance

phil

it's not pretty can utilize require import file(s)

require base_path().`/../rest/models/restapimodel.php`; class adminmodel extends restapimodel { protected $connection = 'application_1_database'; // statistical methods // database manipulation // etc. }

or can autload models of rest api using composer. composer.json in admin application this:

// ... "autoload": { "classmap": [ "app/commands", "app/controllers", "app/models", "../../rest/app/models", "app/database/migrations", // ... ] }, // ...

(after changing autoload section create sure run composer dump-autoload)

php rest laravel eloquent

No comments:

Post a Comment