Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

Laravel Model of Jens Segers is one possible solution to your requirement:

  • Laravel like Model without database!

I presume your external source is a restful API you need to wrap.

Excerpt:

class User extends Model {

    protected $hidden = ['password'];

    protected $casts ['age' => 'integer'];

    public function save()
    {
        return API::post('/items', $this->attributes);
    }

    public function setBirthdayAttribute($value)
    {
        $this->attributes['birthday'] = strtotime($value);
    }

    public function getBirthdayAttribute($value)
    {
        return new DateTime("@$value");
    }

    public function getAgeAttribute($value)
    {
        return $this->birthday->diff(new DateTime('now'))->y;
    }
}

$item = new User(array('name' => 'john'));
$item->password = 'bar';

echo $item; // {"name":"john"}
Last updated 9 years ago.
0

Thanks menjaraz for replying!

This looks quite interesting. I am actually after something that will just read data from remote server. I will modify this and check it out.

Thanks again, Cheers, Nick

0

grandehombre said:

Thanks menjaraz for replying!

This looks quite interesting. I am actually after something that will just read data from remote server. I will modify this and check it out.

Thanks again, Cheers, Nick

Glad to help you.

Please don't forget to give back: Share your findings ;-)

0

@mejaraz this looks really promising; I am currently in the planning stage of an app that consumes a couple of API end points and this could certainly make developing it a lot faster.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.