Skip to main content

Recursive query in Laravel

<?php/** * Created by PhpStorm. * User: Zafar Hayat * Date: 6/26/2020 * Time: 7:06 PM */
namespace App\Services;
use Illuminate\Support\Facades\DB;
class FileWithDeepSearch{    /**     * @var PHPFunction     */    private $PHPFunction;    /**     * @var Common     */    private $common;    /**     * @var Filters     */    private $filters;
    public function __construct(        PHPFunction $PHPFunction,        Common $common,        Filters $filters    ) {        $this->PHPFunction = $PHPFunction;        $this->common = $common;        $this->filters = $filters;    }
    public function getQuery(array $data)    {        $currentDirectoryFilesQuery = $this->getCurrentDirectoryFilesQuery($data);        $recursiveQuery = $this->getRecursiveQuery($data);        $recursiveQuery = $recursiveQuery->unionAll($currentDirectoryFilesQuery);        return $recursiveQuery;    }
    private function getCurrentDirectoryFilesQuery(array $data)    {        $q = DB::table('files_directories as fd')            ->select('f.id', 'f.name', 'f.created_by', 'f.created_at', 'f.updated_at', 'f.file_type', 'f.file_size', 'f.business_date', 'fd.ref_id')            ->selectRaw("1 as is_file")            ->join('files as f', 'f.id', 'fd.file_id')            ->whereRaw($this->common->applyWhere('fd.directory_id', $data['folder_id']))            ->whereRaw('fd.is_current = true');
        $this->filters->applyBusinessDateRangeFilter($q, $data);
        return $q;    }
    public function getRecursiveQuery(array $data)    {        $query = DB::table('directories')            ->select('id', 'name', 'parent_id')            ->whereRaw($this->common->applyWhere('parent_id', $data['folder_id']))            ->unionAll(                DB::table('directories  as d')                    ->select('d.id', 'd.name', 'd.parent_id')                    ->join('tree', 'tree.id', '=', 'd.parent_id')            );
        $builder = new \Staudenmeir\LaravelCte\Query\Builder(app('db')->connection());

        $builder->from('tree')            ->select('f.id', 'f.name', 'f.created_by', 'f.created_at', 'f.updated_at', 'f.file_type', 'f.file_size', 'f.business_date', 'fd.ref_id')            ->selectRaw("1 as is_file")            ->withRecursiveExpression('tree', $query)            ->join('files_directories as fd', 'fd.directory_id', 'tree.id')            ->join('files as f', 'fd.file_id', 'f.id')            ->whereRaw('fd.is_current = true');
        $this->filters->applyBusinessDateRangeFilter($builder, $data);
        return $builder;    }}

Comments

Popular posts from this blog

How To Update PHP In XAMPP

 downloaded the version of PHP that I wanted (7.1.17) and then I strategically replaced the one I had in XAMPP with it. Here are the steps I followed. Download your desired PHP binary from  here . Make sure you download the same build type as your current version. If you don’t know what this is, go ahead and download an  x86 Thread Safe  version since most XAMPP installations have that build. In my case, I downloaded the 7.1.17 VC14 x86 Thread Safe  build. Extract the contents of the Zip file. Create a backup of your current  xampp/php  folder. I called mine php-backup7.1.2 Still inside /xampp, create a new php folder, then copy the contents of the extracted zip file into it. If you have custom configurations in the php.ini file, copy and replace it from your old php folder to the new one. If you didn’t previoisly edit the your php.ini, then skip this step. In my case I had previously installed drivers for sql server and defined them in my php....

Jmeter

JMeter Advantages Open source license : JMeter is totally free,  allows developer use the source code for the development Friendly GUI : JMeter is extremely easy to use and doesn't take time to get familiar with it Platform independent : JMeter is 100% pure Java desktop application. So it can run on multiple platforms Full multithreading framework . JMeter allows concurrent and simultaneous sampling of different functions by a separate thread group Visualize Test Result:  Test result can be displayed in a different format such as chart, table, tree and log file Easy installation : You just copy and run the *.bat file to run JMeter. No installation needed. Highly Extensible : You can write your own tests. JMeter also supports visualization plugins allow you to extend your testing Multiple testing strategy : JMeter supports many testing strategies such as  Load Testing , Distributed Testing, and  Functional Testing . Simulation : JMeter can simulate mul...