How to implement this query in laravel?

laravel raw query with parameters
laravel db::query
laravel subquery
laravel eloquent
laravel eloquent join
laravel db::select count
print query in laravel
laravel multiple where
select *
from tr_sewaiklan
where '2018-12-09' BETWEEN tgl_mulai AND tgl_selesai
DB::tabe('tr_swaiklan')->where('2018-12-09', '>', $tgl_mulai)->where('2018-12-09', '<', $tgl_selesai)->get();

the <> Operator might be used too

it's quite well described in the official documentation: https://laravel.com/docs/5.7/queries#where-clauses

Database: Query Builder - Laravel, How to use raw queries safely. Luckily, Laravel's query builder has the tools we need to safely run such queries. A key concern when writing our own queries  How do I implement this select query in laravel? SELECT `kilometer` FROM `tyres` WHERE `usage`=1 ORDER BY id DESC LIMIT 1

See Laravel Eloquent how to use between operator

to test in tinker without model, try

\DB::table('table')->whereBetween('date_field', ['2018-12-09', '2019-01-01'])->get();


from comment

DB::table('tr_sewaiklan')->where(function ($query) {
    $query
        ->where('tgl_mulai', '<', '2018-12-09')
        ->where('tgl_selesai', '>', '2018-12-09');
});

Basic Database Usage - Laravel, without sanitizing it. This leaves us open to attack! How to implement Full-Text search in Laravel. To start implementing Full-Text search in Laravel 4 we will have to take care of a few things: If you are not using MySQL 5.6+ we must set the Database Engine to MyISAM instead of InnoDB. We have to set up the migration and add the Full-Text index. We must add a search function in our controller.

Finally i solved my problem with raw expression not with eloquent because whereBetween format is field_date and then value_date but in my case my query format is value_date and then field_date.

thanks for your help guys..

DB::select(DB::raw("SELECT a.* FROM tr_sewaiklan a LEFT JOIN tb_iklanposisi b ON a.id_posisi=b.id WHERE '".date('Y-m-d')."' BETWEEN tgl_mulai AND tgl_selesai"));

Database: Getting Started - Laravel, () is used to make arbitrary SQL commands which aren't parsed any further by the query builder. They therefore can create a vector for attack via SQL injection. In this post we are share with you how to implement full calendar (JavaScript Event Calendar) in laravel 5.5. for use full calendar we will represent our daily tasks, events and schedule one daily…

Raw Queries in Laravel, provides a convenient, fluent interface to creating and running database queries. It can be used to perform most database operations in your application and works on all supported database systems. Laravel makes implementing authentication very simple. In fact, almost everything is configured for you out of the box. The authentication configuration file is located at config/auth.php , which contains several well documented options for tweaking the behavior of the authentication services.

Why to use DB::raw inside DB::select in Laravel?, DB::tabe('tr_swaiklan')->where('2018-12-09', '>', $tgl_mulai)->where('2018-12-09'​, '<', $tgl_selesai)->get();. the <> Operator might be used too. How to implement query caching in laravel I am trying to implement caching in my php/laravel application. I am using the repository pattern along with laravel.

How to implement this query in laravel?, Laravel has a great database mechanism called Eloquent, also a powerful Query Builder, but sometimes it makes sense to just use plain SQL,  How to implement search function in Laravel 5.4 0 0

Comments
  • You should add code of your model and the code of what you have tried so far.
  • stackoverflow.com/questions/26746918/…
  • nope dude, because whereBetween format is field_date and then array value, but in my query format is value_date and then field_date...
  • thanks for help but your query doesnt work.. but finally i use raw expression
  • nope dude, because whereBetween format is field_date and then array value, but in my query format is value_date and then field_date...
  • Sorry, misread your question, my bad. If you want an alternative to raw queries you could use a where closure, something like DB::table('tr_sewaiklan')->where(function ($query) { $query ->where('tgl_mulai', '<', '2018-12-09') ->where('tgl_selesai', '>', '2018-12-09'); }); If your date is really a variable you use () it in the closure
  • date('Y-m-d') - Why not just use CURDATE()?