V
V
Viktor Grachev2015-02-25 11:11:42
Laravel
Viktor Grachev, 2015-02-25 11:11:42

How in Laravel 4 to sort requests intended for a group of users?

Good afternoon dear colleagues! I've been struggling with the task for a week now and I can't solve it) Please tell me how to sort applications intended for a group of users. In theory, when a verifier enters the site, he should see only those applications that are intended for him. I have a form where the user fills in the data and selects to whom this application is assigned.
600332ccb9cc4e06a84c110106add15c.png
Application data is stored in the database and the list of users from the select is stored in this way in the database
a:3:{i:0;s:2:"19";i:1;s:2:"20";i:2;s: 2:"23";} their id's are collected in a string. Next, I select all requests from the database and select all fields with user id, they look like this:
e5c3ab345d8745d3a409a84dc5604de8.png
The controller looks like this:

public function application()
    {
       $user = Sentry::getUser();
        $userId = $user->id;
        $recipient = DB::table('posts')->lists('recipient');
        $posts = Post::all();
        return View::make('applications')->with(array('posts' => $posts, 'recipient' => $recipient, 'userId' => $userId));
    }

Further, in the form, I try to display the applications that the reviewer should see based on his id in this way:
@foreach ($recipient as $recent)
       <?php $recentid = unserialize($recent); ?>
                 @foreach($recentid as $user)
                          @if($userId == $user)
                                   @foreach ($posts as $post)
                                           <div class="panel-body">ТЕЛО ЗАЯВКИ</div>    
                                   @endforeach
                         @endif
                  @endforeach
@endforeach

At the output, I get a whole bunch of applications instead of 15 that are in the database, and taking into account that they need to be sorted, even less) Please tell me if I'm doing it right that I store users as a string in the database or is it not worth racking my brains with this or should I do everything differently? And is there a way to sort applications and compare them with users in dynamics? I would be glad for any tips and methods for solving the problem, as I tried a whole bunch of options and not one solved my problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2015-02-25
@azuron

It is necessary to make the table user_order
user_id | order_id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question