GithubHelp home page GithubHelp logo

Comments (18)

Anahkiasen avatar Anahkiasen commented on August 15, 2024

Yup, Former uses the __toString method of a model to render it in a list, unless you specify otherwise (like here with username). Somehow it got highjacked and used the default output for models in Laravel 4 (json).
I'll check it out.

EDIT : Apparently the username can be bypassed if the isset fails. You sure there's an  username method or attribute ? (stupid question but you never know)

from former.

JohnCHarrington avatar JohnCHarrington commented on August 15, 2024

Ah ok, nice to learn more about how it does things, I find it much easier to use if I really know what it's doing! :) Thanks very much

from former.

Anahkiasen avatar Anahkiasen commented on August 15, 2024

...but it's still broken or ?

from former.

JohnCHarrington avatar JohnCHarrington commented on August 15, 2024

Yeah, still broken! The fact that I like to know what's going on is totally unrelated really lol

from former.

Anahkiasen avatar Anahkiasen commented on August 15, 2024

Did you check there was an username attribute or method on your returned models ?

from former.

JohnCHarrington avatar JohnCHarrington commented on August 15, 2024

It's right there in the JSON output, as is the id :)

from former.

Anahkiasen avatar Anahkiasen commented on August 15, 2024

Ah fuck, yeah, didn't even notice. Well that's just weird.Maybe Former doesn't like the new Eloquent Collections, will write a test for it see if it fails.

from former.

Anahkiasen avatar Anahkiasen commented on August 15, 2024

Just pushed a change, can you try again ?

from former.

JohnCHarrington avatar JohnCHarrington commented on August 15, 2024

Notice: Undefined variable: app in /Applications/MAMP/Web/Sites/LearnLaravel/vendor/anahkiasen/former/src/Former/FormerServiceProvider.php line 48

from former.

Anahkiasen avatar Anahkiasen commented on August 15, 2024

I'm a moron. Try again.

from former.

JohnCHarrington avatar JohnCHarrington commented on August 15, 2024

Lol, you fixed that one, but I still get JSON

from former.

Anahkiasen avatar Anahkiasen commented on August 15, 2024

Ok I'm gonna setup a fresh app and try to reproduce it.

from former.

JohnCHarrington avatar JohnCHarrington commented on August 15, 2024

If it helps, here is a var_dump off the Eloquent collection:

object(Illuminate\Database\Eloquent\Collection)#165 (2) { ["items":protected]=> array(1) { [0]=> object(User)#158 (14) { ["table":protected]=> string(5) "users" ["hidden":protected]=> array(2) { [0]=> string(8) "password" [1]=> string(10) "auth_level" } ["connection":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["timestamps"]=> bool(true) ["attributes":protected]=> array(7) { ["id"]=> string(1) "1" ["username"]=> string(5) "admin" ["password"]=> string(60) "$2a$08$mz9ZA7etUBTj4KcRgVZ3RO4nsph6lfavBqQpQYqOg2yiE5zz1bFMu" ["name"]=> string(5) "Admin" ["created_at"]=> string(19) "0000-00-00 00:00:00" ["updated_at"]=> string(19) "0000-00-00 00:00:00" ["auth_level"]=> string(3) "100" } ["original":protected]=> array(7) { ["id"]=> string(1) "1" ["username"]=> string(5) "admin" ["password"]=> string(60) "$2a$08$mz9ZA7etUBTj4KcRgVZ3RO4nsph6lfavBqQpQYqOg2yiE5zz1bFMu" ["name"]=> string(5) "Admin" ["created_at"]=> string(19) "0000-00-00 00:00:00" ["updated_at"]=> string(19) "0000-00-00 00:00:00" ["auth_level"]=> string(3) "100" } ["relations":protected]=> array(0) { } ["fillable":protected]=> array(0) { } ["guarded":protected]=> array(0) { } ["dates":protected]=> array(0) { } ["exists"]=> bool(true) } } ["dictionary":protected]=> array(0) { } } 

["items":protected] and ["dictionary":protected], the 2 top level arrays, are being pulled out of that and made into 's, which are then populated with their contents.

["items":protected]=> array(1) { [0]=> object(User)#158 (14) ......
["dictionary":protected]=> array(0)

from former.

Anahkiasen avatar Anahkiasen commented on August 15, 2024

SO, apparently instanceof doesn't like when you don't use the full namespace. Which is kind of logical actually. Should work now.

from former.

JohnCHarrington avatar JohnCHarrington commented on August 15, 2024

Ah, awesome :)

from former.

JohnCHarrington avatar JohnCHarrington commented on August 15, 2024

All works perfectly, thanks very much :)

from former.

Anahkiasen avatar Anahkiasen commented on August 15, 2024

No problem :)
I redid my tests so that the working of Former didn't depend of how dependencies were working, problem is now I'm never sure the tests actually reflect how Former works in real life. Guess it's a trade-off.

from former.

JohnCHarrington avatar JohnCHarrington commented on August 15, 2024

Yeah, the only real solution is two sets of tests, but that's rather a lot more work!

from former.

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.