Support the ongoing development of Laravel.io →
Database Eloquent

There is one problem which I can't solve. I need to show a response only for users whose user_id was written in 'recipient' field.

First step : I am writing the user_id into a table using json array

Appform.blade.php

       <div class="form-group">
    {{ Form::label('recipient', 'Checking') }}
   <select id="recipient" name="recipient[]" required class="form-control" multiple>
 @foreach ($recipient as $user)
     <option value="{{ $user->id }}">{{ $user->first_name }}</option>
 @endforeach
  </select>
@if($errors->has('recipient'))
 {{ $errors->first('recipient') }}
 @endif
</div>

Controller.php

   public function postAppForm()
{
$data = Input::all();
$cityId             = Input::get('city');
$recipient          = Input::get('recipient');

$rules = array(
    'city'           => 'required',
    'recipient'      => 'required',
);

$recipient1 = json_encode($recipient);

$validator = Validator::make($data, $rules);
if($validator->passes()) {

    $posts = new Posts;
    $posts->recipient   = $recipient1;
    $city               = City::find($cityId);

    $city->posts()->save($posts);
    return Redirect::to('appform')->with('global-success', 'Заявка отпарвленна');

} else {
    return Redirect::back()->withErrors($validator)->withInput();
}


public function application()

{

     $recipient = DB::table('posts')->groupBy('recipient')-   >lists('recipient');

 }

And I get ["18","19","20"] - user_id for my post, but I don't know how to show my posts only for that users_id?

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Adoafw adoafw Joined 21 Feb 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.