How to get the id of a model in octobercms?

by darrion.kuhn , in category: PHP CMS , a year ago

How to get the id of a model in octobercms?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lily , a year ago

@darrion.kuhn 

To get the ID of a model in OctoberCMS, you can use the getAttribute() method on the model instance.


Here is an example of how to get the ID of a model:

1
2
$myModel = MyModel::find($modelId);
$modelId = $myModel->getAttribute('id');


In the above example, MyModel is the name of your model, and $modelId is the variable that will store the ID of the model. You should replace MyModel with the actual name of your model class.


Note that the getAttribute('id') method will only work if the model has the id attribute defined. If your model uses a different primary key name, replace 'id' in the above example with the name of your primary key attribute.

Related Threads:

How to get the id of current saved model in laravel?
How to return ajax data request by id in octobercms?
How to override a model properties and methods in octobercms?
How to display username instead of id in a list in octobercms?
How to get value from another model in codeigniter?
How to get cookie in octobercms?