Skip to content

Instantly share code, notes, and snippets.

@alissonsilvas
Created February 2, 2017 16:48
Show Gist options
  • Save alissonsilvas/e007ef897cf63f3d966fdd031a26707c to your computer and use it in GitHub Desktop.
Save alissonsilvas/e007ef897cf63f3d966fdd031a26707c to your computer and use it in GitHub Desktop.
Problemas com uma consulta laravel 5.4
//Model
namespace App;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
class Tblpreco extends Model
{
public $fillable = ['emissao','hsemissao','users_id','categoria','valor','vigencia'];
protected $dates = ['vigencia','emissao'];
protected $table = 'tblpreco';
public $timestamps = false;
public function setValorAttribute($valor)
{
$source = array(',','.');
$replace = array('.','');
$this->attributes['valor'] = str_replace($source,$replace, $valor);
}
public function setVigenciaAttribute($vigencia)
{
$this->attributes['vigencia'] = Carbon::createFromFormat('d/m/Y', $vigencia)->toDateString();
}
}
//Controller
public function index(Request $request)
{
$dtinicial = $request['dtinicial'];
$dtfinal = $request['dtfinal'];
$dtinicial = Carbon::parse($dtinicial)->format('d/m/Y');
$dtfinal = Carbon::parse($dtfinal)->format('d/m/Y');
$tblprecos = Tblpreco::whereBetween('vigencia', array($dtinicial, $dtfinal))
->paginate(10);
dd($tblprecos);
return view('tblpreco.list',compact('tblprecos'))
->with('i', ($request->input('page', 1) - 1) * 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment