How can Filter a data from database?

Posted by

In this tutorial, I’m going to learn filter a data from database. so follow this tutorial in this tutorial we have mentioned it in a very easy way.

Here is a function in which I want to see the data in which any field of the social site is filled,  If not then data is not shown in the blade page.


   public function influencerProfileDashboard()
    {
        $data = DB::table('addprofiles')
            ->leftJoin('countries', 'addprofiles.country_id', '=', 'countries.country_id')
            ->leftJoin('states', 'addprofiles.state_id', '=', 'states.state_id')
            ->leftJoin('cities', 'addprofiles.city_id', '=', 'cities.city_id')
            ->leftJoin('users', 'addprofiles.user_id', '=', 'users.id')
            ->select('addprofiles.*', 'countries.country_name', 'states.state_name', 'cities.city_name', 'users.name', 'users.email', 'addprofiles.file_pic')
            ->orderBy('id', 'desc')
            ->get();
        $filteredData = $data->filter(function ($item) {
            return !empty($item->facebook) || !empty($item->twitter) || !empty($item->youtube) || !empty($item->wordpress) || !empty($item->tumblr) || !empty($item->instagram) || !empty($item->quora) || !empty($item->pinterest) || !empty($item->reddit) || !empty($item->koo) || !empty($item->scoopit) || !empty($item->slashdot) || !empty($item->telegram) || !empty($item->fb_grp) || !empty($item->linkedin_grp) || !empty($item->linkedin) || !empty($item->roposo) || !empty($item->chingari) || !empty($item->mitron);
        });

        return view('pages.influencer', compact('filteredData'));
    }