A
A
Andrey Sokolov2014-08-12 21:45:09
Laravel
Andrey Sokolov, 2014-08-12 21:45:09

Laravel: How to make a handler-model?

Good afternoon, this question is still ripe in CodeIgniter, I worked with models as follows:
After creating the model and the function in it, I applied by passing the parameters
$this->model_my->function($param...$params)
to the output. what the function returns in the model, and already gave it to the view.
Attention the question is how to implement this in Laravel? Throw a guide at me, otherwise I didn’t find it =(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Brezhnev, 2014-08-13
@eX1stenZ

<?php

class MySuperModel extends Eloquent
{
    public function mySuperFunction($param1 = null, $param2 = null)
    {
        return [$param1, $param2, $this->id];
    }
}

$model = MySuperModel::find(1); // 1 это ID модели в базе

$result = $model->mySuperFunction(100, 200);

print_r($result);

/*
    Array
    (
        [0] => 100
        [1] => 200
        [2] => 1 // ID модели $this->id
    )
*/

S
Sergey, 2014-08-12
Protko @Fesor

Can't you implement a method in a class? IMHO depending on what you are doing there. Maybe this thing should be taken out in services. In models (or rather in entities) there should be only what belongs to the model.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question