Wednesday, 28 August 2019

Laravel and condition on JOIN && add paramteres to laravel commands

Laravel add and condition on JOIN :

$results = DB::table('rooms')
                     ->distinct()
                     ->leftJoin('bookings', function($join)
                         {
                             $join->on('rooms.id', '=', 'bookings.room_type_id');
                             $join->on('arrival','>=',DB::raw("'2012-05-01'"));
                             $join->on('arrival','<=',DB::raw("'2012-05-10'"));
                             $join->on('departure','>=',DB::raw("'2012-05-01'"));
                             $join->on('departure','<=',DB::raw("'2012-05-10'"));
                         })
                     ->where('bookings.room_type_id', '=', NULL)
                     ->get();


https://stackoverflow.com/questions/16848987/a-join-with-additional-conditions-using-query-builder-or-eloquent


Laravel add parameter on Commands :

command class:


        protected $signature = 'command:command {--parameter1=} {--parameter2=}'
        // Retrieve command
        $this->option('parameter1');
         $this->option('parameter2');   

https://stackoverflow.com/questions/46670304/laravel-command-only-optional-argument
https://stillat.com/blog/2016/12/01/laravel-artisan-command-input-and-command-signatures

No comments:

Post a comment