1

The database stores information about co-executors and observers in the form '-1-10-20-30-40-50-60-" this is the user_id of the user. How can I check with such data whether the user is in this list and whether he can view the content?

            $tasks = Tasks::with('uprcomp','street','houses', 'otvets', 'created_user')
            ->where('status','0')
            ->where(function($query) use ($user_id) {
                $query->where('user_id',$user_id)
                            ->orWhere('f8820',$user_id) // Responsible
                            ->orWhere('f8830',$user_id) // Observers
                            ->orWhere('f8840',$user_id) // Co - executors
                            ->orWhere('f11580',$user_id); // Observers
            })
            ->orderBy('id', 'desc')->paginate(25);

Thanks!

Rondo
  • 11
  • 2
  • Can you share some data and the expected output – SelVazi Jan 30 '23 at 09:19
  • 3
    I would recommend redisigning this part of the database to allow this sort of query to be easily done. – Nigel Ren Jan 30 '23 at 09:28
  • The CRM system implied the presence of responsible and executors, that is, 2 people and two cells. At this moment, it is necessary to introduce more observers and co-executors. Co-executors and observers are stored in the database as '-1-10-20-30-40-' where the number is the user ID. I need a query to the database where it will be checked whether the user has access to this task or not, and of course in the end there should be an array where there are only tasks that the user has access to – Rondo Jan 30 '23 at 09:32
  • share tasks table with sample data. – Insane Skull Jan 30 '23 at 09:51
  • @InsaneSkull https://imgur.com/nW1GwKg.png – Rondo Jan 31 '23 at 05:59
  • Either store your data as comma separated values so you can use `find_in_set()` or https://stackoverflow.com/questions/68055817/mysql-find-value-in-a-separated-hyphen-list `OR` https://stackoverflow.com/questions/34854218/how-to-get-data-from-hyphen-separated-value-in-mysql-with-laravel – Insane Skull Jan 31 '23 at 06:07

0 Answers0