How to make none-database model two attributes in Laravel
up vote
4
down vote
favorite
I'm a newbie in Laravel. Please guide me.
Port is a Model and Coordinates is a none database Model. There are 2 floats (lat and long) in the Port Model. When a Port is loaded from the database, the 2 floats are cast to a Coordinates object.
My first question is, how do I make a non-database model with two attributes?
My second question is, how do I make a cast 2 floats in Port Model with Coordinates object?
Here is my Code Coordinates Model none-database Model with two attributes
class Coordinates extends Model
{
//Add attribute
protected $attributes = ['latitude', 'longitude'];
}
and here is Port Model With
class Port extends ContractsAppModel
{
protected $coordinates = Coordinates::class;
protected $fillable=[
'un_latitude',
'un_longitude',
];
function __construct(array $attributes = array())
{
$this->coordinates = Coordinates::class;
$this->coordinates->latitude = $attributes["un_latitude"];
$this->coordinates->longitude = $attributes["un_longitude"];
}
}
laravel laravel-5 laravel-4 laravel-5.1
add a comment |
up vote
4
down vote
favorite
I'm a newbie in Laravel. Please guide me.
Port is a Model and Coordinates is a none database Model. There are 2 floats (lat and long) in the Port Model. When a Port is loaded from the database, the 2 floats are cast to a Coordinates object.
My first question is, how do I make a non-database model with two attributes?
My second question is, how do I make a cast 2 floats in Port Model with Coordinates object?
Here is my Code Coordinates Model none-database Model with two attributes
class Coordinates extends Model
{
//Add attribute
protected $attributes = ['latitude', 'longitude'];
}
and here is Port Model With
class Port extends ContractsAppModel
{
protected $coordinates = Coordinates::class;
protected $fillable=[
'un_latitude',
'un_longitude',
];
function __construct(array $attributes = array())
{
$this->coordinates = Coordinates::class;
$this->coordinates->latitude = $attributes["un_latitude"];
$this->coordinates->longitude = $attributes["un_longitude"];
}
}
laravel laravel-5 laravel-4 laravel-5.1
3
Please rewrite your question with dots and commas. It's hard to read your question.
– Ruub
Nov 6 at 10:58
1
I have Done now please explain it. @Ruub
– Kashif Ahmed
Nov 6 at 11:32
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I'm a newbie in Laravel. Please guide me.
Port is a Model and Coordinates is a none database Model. There are 2 floats (lat and long) in the Port Model. When a Port is loaded from the database, the 2 floats are cast to a Coordinates object.
My first question is, how do I make a non-database model with two attributes?
My second question is, how do I make a cast 2 floats in Port Model with Coordinates object?
Here is my Code Coordinates Model none-database Model with two attributes
class Coordinates extends Model
{
//Add attribute
protected $attributes = ['latitude', 'longitude'];
}
and here is Port Model With
class Port extends ContractsAppModel
{
protected $coordinates = Coordinates::class;
protected $fillable=[
'un_latitude',
'un_longitude',
];
function __construct(array $attributes = array())
{
$this->coordinates = Coordinates::class;
$this->coordinates->latitude = $attributes["un_latitude"];
$this->coordinates->longitude = $attributes["un_longitude"];
}
}
laravel laravel-5 laravel-4 laravel-5.1
I'm a newbie in Laravel. Please guide me.
Port is a Model and Coordinates is a none database Model. There are 2 floats (lat and long) in the Port Model. When a Port is loaded from the database, the 2 floats are cast to a Coordinates object.
My first question is, how do I make a non-database model with two attributes?
My second question is, how do I make a cast 2 floats in Port Model with Coordinates object?
Here is my Code Coordinates Model none-database Model with two attributes
class Coordinates extends Model
{
//Add attribute
protected $attributes = ['latitude', 'longitude'];
}
and here is Port Model With
class Port extends ContractsAppModel
{
protected $coordinates = Coordinates::class;
protected $fillable=[
'un_latitude',
'un_longitude',
];
function __construct(array $attributes = array())
{
$this->coordinates = Coordinates::class;
$this->coordinates->latitude = $attributes["un_latitude"];
$this->coordinates->longitude = $attributes["un_longitude"];
}
}
laravel laravel-5 laravel-4 laravel-5.1
laravel laravel-5 laravel-4 laravel-5.1
edited Nov 7 at 6:14
asked Nov 6 at 10:51
Kashif Ahmed
356
356
3
Please rewrite your question with dots and commas. It's hard to read your question.
– Ruub
Nov 6 at 10:58
1
I have Done now please explain it. @Ruub
– Kashif Ahmed
Nov 6 at 11:32
add a comment |
3
Please rewrite your question with dots and commas. It's hard to read your question.
– Ruub
Nov 6 at 10:58
1
I have Done now please explain it. @Ruub
– Kashif Ahmed
Nov 6 at 11:32
3
3
Please rewrite your question with dots and commas. It's hard to read your question.
– Ruub
Nov 6 at 10:58
Please rewrite your question with dots and commas. It's hard to read your question.
– Ruub
Nov 6 at 10:58
1
1
I have Done now please explain it. @Ruub
– Kashif Ahmed
Nov 6 at 11:32
I have Done now please explain it. @Ruub
– Kashif Ahmed
Nov 6 at 11:32
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53170404%2fhow-to-make-none-database-model-two-attributes-in-laravel%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
3
Please rewrite your question with dots and commas. It's hard to read your question.
– Ruub
Nov 6 at 10:58
1
I have Done now please explain it. @Ruub
– Kashif Ahmed
Nov 6 at 11:32