In form below my user share document access with other users.
How to increase my selector to show me only user who are not shared with this document yet? Document and User has pivot table document_user
<select type="text" name="user" class="uk-select">
<option disabled selected>Choose from contacts</option>
#foreach($company->users as $contact)
//#if (something)
<option value="{{ $contact->id }}">{{ $contact->first_name}} {{ $contact->last_name}}</option>
#andif
#endforeach
</select>
Document = $document
Tables:
user:
id
name
document:
id;
company_id
name
document_user:
- company_id
- user_id
Try this..
From your table structure I believe you should have the many to many relation.
User.php
public function documents()
{
return $this->belongsToMany(Document::class, 'document_user');
}
xx.blade.php
<select type="text" name="user" class="uk-select">
<option disabled selected>Choose from contacts</option>
#foreach($company->users as $contact)
#if(!in_array($contact->id, $document->users->pluck('id')->toArray()))
<option value="{{ $contact->id }}">
{{ $contact->first_name}} {{ $contact->last_name}}
</option>
#endif
#endforeach
</select>
Related
I am using multiselect dropdown but not able to get old values(by using old('') in laravel blade)on submit.Please tell where i am doing wrong.Below i am sharing code.
<div class="form-group">
<label for="integration">Integration</label>
<div class="select2-purple">
<select id="integration" class="form-control form-select form-select-lg col-lg-12 select2" multiple="multiple" aria-label=".form-select-lg example" data-dropdown-css-class="select2-purple" name="integration[]">
<option value=''>Select Integration</option>
#foreach($integartion as $integartions)
<option value="{{ $integartions->ecom_channel }}" #if(isset($company) && in_array($integartions->ecom_channel, $CmpIntegartion) ) selected #endif>{{ $integartions->ecom_channel }}</option>
#endforeach
</select>
#if ($errors->has('integration'))
<span class="text-danger">{{ $errors->first('integration') }}</span>
#endif
</div>
</div>
<select name="integration[]">
<option value=''>Select Integration</option>
#foreach($integartion as $integartions)
<option value="{{ $integartions->ecom_channel }}" #if(old('integration') && is_array(old('integration')) && in_array($integartions->ecom_channel, old('integration')) selected #endif>{{ $integartions-> ecom_channel}}</option>
#endforeach
</select >
Your data will be stored like this in old:
integration[0] = somevalue,
integration[1] = somevalue
So you first check if your old('integration') is not null,
then you check if its an array, then you check if the current item of loop exists inside that array!!
I have 2 multiple value select lists that I pass users between them using jquery.
<select multiple="multiple" id="ListAllUsers" class="form-control">
#foreach ($users as $user)
<option class="content" value="{{ $user->id }}">{{ $user->name }}</option>
#endforeach
</select>
<select name="user_id[]" required multiple="multiple" id="SelectedUsers" class="form-control">
#if (!empty(old('user_id')) && $create_form)
#foreach ($old_value_users as $old_user)
<option class="content" value="{{ $old_user->id }}">{{ $old_user->name }}</option>
#endforeach
#endif
</select>
Now, my issue is that when I go and pass the old('user_id') value in the whereIn query, I only get the first result of the array instead of all of the results that are passed in.
$old_users_id = [old('user_id')];
$old_value_users = User::whereIn('id', $old_users_id)->get();
If I replace $old_users_id = [old('user_id')] with $old_users_id = [1,2,3], it works like a charm. I have dd(old('user_id')) and it is indeed an array, so I do not understand what is the hick-up!
Since old('user_id') is an array, you should not put it in an array. Try this;
You shold provide an empty array if old('user_id') is null.
$old_users_id = old('user_id')?old('user_id'):[];
$old_value_users = User::whereIn('id', $old_users_id)->get();
+ point
Instead of whereIn try with whereIntegerInRaw if you are adding a large array of integer bindings to your query.For more check documentation
Something like this one
<select class="custom-select chosen-select {{ $errors -> has('add_project_owner') ? 'is-invalid' : '' }}" name="add_project_owner[]" id="add_project_owner" multiple>
<option value="">choose</option>
#foreach ($owners as $owner)
<option value="{{ $owner -> emp_name }}" {{ (collect(old('add_project_owner'))->contains($owner -> emp_name)) ? 'selected' : '' }}>{{ $owner -> emp_name }}</option>
#endforeach
</select>
I'm trying to insert data into a database with an option menu.
<select class="form-control" name="tim">
#foreach ($tim as $t)
<option value="{{ $t->id }}">{{ $t->name }}</option>
#endforeach
</select>
and this the controller
$data=new Modelverif();
$data->id_profil=$request->id;
$data->$id_pegawai=$request->get('tim');
$data->save();
how to input database with option menu with array?
Blade.php
<select class="form-control" name="tim">
#foreach ($tim as $t)
<option value="{{ $t->id }}">{{ $t->name }}</option>
#endforeach
</select>
the controller
$data=new Modelverif();
$data->id_profil=$request->id;
$data->$id_pegawai=$request->tim; //Or $data->$id_pegawai= $request->input('tim');
$data->save();
I think for this you need to convert your select into multiple choice.
<select class="form-control" multiple name="tim">
it will allow you choose mulitple values from select and give an array of values when you post the data
try this one:
$data=new Modelverif();
$data->id_profil=$request->id;
// assuming you have column name in $id_pegawai
$data->$id_pegawai= $request->input('tim');
// or,
// $data->$id_pegawai= $request->tim;
$data->save();
I'm working on an angular js 2 project and I need to create a dropdown (kinda like a link) wherein if you select an option it will trigger an onchange event and redirect the user. Currently I have this:
<select id = "dashboard" onchange="goToPage()" class="form-control">
<option value="" selected disabled>{{ 'Create' | translate }}</option>
<option value="Applicant" >{{ "dashboard.applicant" | translate}}</option>
<option value="Reports">{{ "dashboard.report" | translate}}</option>
</select>
In the select box I want the 'Create' option to always be selected even if the applicant selects Applicant or Reports. How can I do this behavior?
You can't cast onchange if user can't change selected value at all, but you can place inside your function this line document.getElementById("dashboard").selectedIndex = 0; which will select first option again:
function goToPage(){
document.getElementById("dashboard").selectedIndex = 0;
}
<select id = "dashboard" onchange="goToPage()" class="form-control">
<option value="" selected disabled>{{ 'Create' | translate }}</option>
<option value="Applicant" >{{ "dashboard.applicant" | translate}}</option>
<option value="Reports" >{{ "dashboard.report" | translate}}</option>
</select>
Iam trying to edit student details.
iam fetch values from database. blood group fetch from database to display select box. and also display other blood groups in same select box.
select class="form-control" name="studbldgrp" id="studbldgrp">
option value="{{$student->studbldgrp}}">{{$student->studbldgrp}}</option>
option value="O+ve">O+ve</option>
option value="O-ve">O-ve</option>
<option value="A+ve">A+ve</option>
<option value="A-ve">A-ve</option>
<option value="B+ve">B+ve</option>
<option value="B-ve">B-ve</option>
<option value="AB+ve">AB+ve</option>
<option value="AB-ve">AB-ve</option>
<option value="Other">Other</option>
</select>
my problem is if im fetch value is A+ ,and display in select box. but it also in option value field.
i no need to again this value(A+)A +ve in select option field.
how to disable this field???
Create an array of your groups. Than iterate over it and don't print value matches $student->studbldgrp.
Array in php:
$groups = array(
'O+ve',
'O-ve',
'A+ve',
'A-ve',
'B+ve',
'B-ve',
'AB+ve',
'AB-ve',
'Other'
);
Blade template:
<select class="form-control" name="studbldgrp" id="studbldgrp">
<option value="{{$student->studbldgrp}}">{{$student->studbldgrp}}</option>
#foreach ($groups as $group)
#if ($group != $struden->studbldgrp)
<option value="{{ $group }}">{{ $group }}</option>
#endif
#endforeach
</select>