GithubHelp home page GithubHelp logo

Comments (4)

rokcarl avatar rokcarl commented on June 9, 2024

You can do it like this (I'll assume this is a User model):

Inside the User model

    public function get_gender_formatted() {
        return (($this->get_attribute('gender') == 0) ? "male" : "female";
    }

Once you do this, you can pretend in your administrator models that you have a column (in your database) gender_formatted, which will give you what you want.

The other way I think you can do it is with Enum (https://github.com/FrozenNode/Laravel-Administrator#enum-1)

    public $edit = array(
        'type' => array(
            'title' => 'Gender',
            'type' => 'enum',
            'options' => array('0' => 'male', '1' => 'female')
        )
    );

from laravel-administrator.

iicmaster avatar iicmaster commented on June 9, 2024

@rokcarl thanks for suggestions but it didn't work both :(

  • for first suggestion Laravel-Administrator call database field directly I can't use Getter & Setter Methods
  • for enum Laravel-Administrator check if options key is numeric it will use value not the key

from laravel-administrator.

rokcarl avatar rokcarl commented on June 9, 2024

Since I think the first suggestion is the way to go, I'll comment on that one.
Administrator doesn't call the database directly but uses the Eloquent model. Therefore, what you put in that model, kind of is the database for the administrator (it uses that). On top of that, I've tried it and it works and also when you download administrator, there is an /examples/application directory that uses the same trick.

That means you either didn't try it or made an error. Look at my suggestion again or follow the code in the /examples/application.

Post back if you made it work.

from laravel-administrator.

janhartigan avatar janhartigan commented on June 9, 2024

Yep as @rokcarl mentions, it's Eloquent all the way. The reason why I made this bundle is so you can use your Eloquent models normally with an administrative interface. If you find any problems where it's not working as you expect Eloquent should, I'd probably consider it a bug. However, @rokcarl is correct in that it should work.

from laravel-administrator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.