You will create a model (Eloquent) with all the pertinent settings of the table that you reference to your model.
Example
<?php
class Log extends Eloquent
{
public $table = 'logs';
public $primaryKey = 'id';
public $timestamps = true;
protected $fillable = array('description');
public function getDates()
{
return array('created_at','updated_at');
}
}
Having a table similar to this layout referencing the Eloquent model above.
CREATE TABLE 'test'.'logs'
(
'id' BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT ,
'description' VARCHAR(255) NOT NULL ,
'created_at' TIMESTAMP NULL ,
'updated_at' TIMESTAMP NULL ,
PRIMARY KEY ('id')
);
Function:
$log = Log::create(array('description' => 'info'));
This line above inserts a record in the table of logs
(the created_at
and updated_at
fields are not entered because they are automatically generated).
This would be the basic operation, where in any Local you could call this line to create a Log. In general you can make a line in BaseController
Log
in all classes that inherited from this BaseController
.
Example:
class BaseController extends Controller {
public function __construct()
{
}
protected function setupLayout()
{
if ( ! is_null($this->layout))
{
$this->layout = View::make($this->layout);
}
}
//método padrão de LogEmail
protected function logEmail($email)
{
return Log::create(array('description' => $email));
}
}
No seu controller
<?php
class BuscaController extends BaseController
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->logEmail('[email protected]');
return Redirect::route('index.home');
}
}
This link on the site itself has all the Eloquent settings and how it should be used.