3
I have the following code
public function getConsultaLocacao()
{
$consulta = LocacaoBanco::where('id',4)->get();
foreach($consulta as $v)
{
echo"aqui->".$v->datalocacao;
}
echo "<br>";
var_dump($v->datalocacao);
}
CODE RESULT
aqui->2019-01-01 00:00:00
string(19)"2019-01-01 00:00:00"
Now look at my database, the id = 4
refers to another line and the laravel
only returns me wrong.
id datalocacao datadevolucao valorlocacao estadodevolucao
4 2019-01-31 00:00:00 2019-01-31 00:00:00 11 nao
Complete code of the model:
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
class LocacaoBanco extends Model
{
protected $table = 'locacao';
public $timestamps = false;
public $datalocacao;
public $datadevolucao;
public $valorlocacao;
public $estadodevolucao;
public $id;
public function __construct() {
$this->datalocacao = "2019-01-01 00:00:00";
$this->datadevolucao = "2019-01-01 00:00:00";
$this->valorlocacao = 5.20;
$this->estadodevolucao = "nao";
$this->id = null;
}
public function setRegLocacao() {
$datalocacao = $this->datalocacao;
$datadevolucao = $this->datadevolucao;
$valorlocacao = $this->valorlocacao;
$estadodevolucao = $this->estadodevolucao;
$id = $this->id;
echo "Insercao da tabela locacao executada";
}
public function setAtualizaLocacao() {
$datalocacao = $this->datalocacao;
$datadevolucao = $this->datadevolucao;
$valorlocacao = $this->valorlocacao;
$estadodevolucao = $this->estadodevolucao;
$id = $this->id;
DB::update("update locacao SET datalocacao = ?,datadevolucao = ?,valorlocacao=?,estadodevolucao=?,id=? ",[$datalocacao,$datadevolucao,$valorlocacao,$estadodevolucao,$id]);
echo "locacao atualizada";
}
public function getConsultaLocacao() {
$consulta = LocacaoBanco::where('id',4)->get();
foreach($consulta as $v) {
echo"aqui->".$v->datalocacao;
}
echo "<br>";
var_dump($v->datalocacao);
}
}
}
?>
Hi @Lorena, do me a favor after the
$consulta = LocacaoBanco::where('id',4)->get();
put this heredd($consulta);
and tell me the result.– Bulfaitelo
If you’re doing it wrong, you’re using Eloquent wrong.
– novic