Laravel Model of Jens Segers is one possible solution to your requirement:
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"}
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
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 ;-)
@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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community