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"];
}

}









share|improve this question




















  • 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

















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"];
}

}









share|improve this question




















  • 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















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"];
}

}









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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




















































































Popular posts from this blog

横浜市

Prokocim

Hungria