Code igniter update function on dropdown menu - codeigniter

i have this update function on my codeigniter
my controller is
public function updatepersonalinfo(){
$id = $_GET['id'];
$data['content'] = $this->Employees_Model->personalinfo($id); // this is current information to be updated
$data['content1'] = $this->Employees_Model->nationality(); // this is select box value
$data['content_view'] = 'Employees/edit_personalinfo';
$this->templates->admin_template($data);
}
then my view for one of the select box is
<select class="form-control" name = "BLOOD_TYPE">
<option value="<?php echo $content->BLOOD_TYPE; ?>"><?php echo $content->BLOOD_TYPE; ?></option>
<option value="A"> A </option>
<option value="B"> B </option>
<option value="AB"> AB </option>
<option value="O"> O </option>
</select>
what happens here is that for example, the value that to be updated is A
it will become
what i wanted to do is, for example, the value i will update to the database is B the update function will show something like this.

Related

laravel livewire select box not working. how can i fix it?

I am making a very simple select box using livewire. This is trying to use wire:model but it doesn't work.
livewire file is
public $city = 'Seoul';
public function mount(){}
public function render()
{
echo 'city : '.$this->city;
return view('livewire.weather', []);
}
and blade file is
<select class="form-control" wire:model="city" name="city">
<option value="Seoul">서울</option>
<option value="Busan">부산</option>
<option value="Daejeon">대전</option>
<option value="Daegu">대구</option>
<option value="Kwangju">광주</option>
<option value="Incheon">인천</option>
<option value="Suwon">수원</option>
<option value="Changwon">창원</option>
<option value="Ulsan">울산</option>
<option value="Andong">안동</option>
<option value="Chuncheon">춘천</option>
<option value="Cheongju">청주</option>
<option value="Jeonju">전주</option>
<option value="Jeju">제주</option>
</select>
How to connect livewire and select box in html?
I don't see what is your problem here. Check network tab - $city should be updated after selecting
public $city = 'Seoul';
public function render()
{
return view('livewire.weather');
}

Laravel : how to explode and showing multiple data in select2

I am using select2 and i want to showing multiple data from database in edit page
#foreach( $userLanguages as $userLanguageTitle)
<option value="{{$user->languages}}">{{$userLanguageTitle}}</option>
#endforeach
But showing me
<select name="languages[]" class="select2 form-control" multiple="multiple" required>
<option value="English,Persian,German" >English</option>
<option value="English,Persian,German" >Persian</option>
<option value="English,Persian,German" >French</option>
<option value="English,Persian,German" >German</option>
<option value="English,Persian,German" >Spanish</option>
<option value="English,Persian,German" >Turkish</option>
<option value="English,Persian,German" >Italian</option>
</select>
I want show selected data in element Like the example below
<select name="languages[]" class="select2 form-control" multiple="multiple" required>
<option value="English" selected >English</option>
<option value="Persian" selected >Persian</option>
<option value="French">French</option>
<option value="German" selected >German</option>
<option value="Spanish" >Spanish</option>
<option value="Turkish" >Turkish</option>
<option value="Italian" >Italian</option>
</select>
Model
public static function getUserlanguages()
{
return [
self::ENGLISH => 'English',
self::PERSIAN => 'Persian',
self::FRENCH => 'French',
self::GERMAN => 'German',
self::SPANISH => 'Spanish',
self::TURKISH => 'Turkish',
self::ITALIAN => 'Italian',
];
}
controller
public function edit(Request $request, $id)
{
$user = User::findOrFail($id);
$userLanguages = User::getUserlanguages();
return view('backend.users.edit', compact('user', 'userLanguages',));
}
Try this, assuming $user->languages is a relation in User model and there is column name in languages table
#foreach($userLanguages as $userLanguageTitle)
<option value="{{$userLanguageTitle}}" {{ (in_array($userLanguageTitle, $user->languages()->pluck('name')->toArray()) ? 'selected' : '') }}>{{$userLanguageTitle}}</option>
#endforeach
<option value="{{$user->languages}}">{{$userLanguageTitle}}</option>
Since you edited the code above, I assume that $user->languages returns all Languages of an User. So it returns either a Collection or an Array but not a single Language item. So you can simply use value="{{$userLanguageTitle}}" to display the name of the language or you use the key of it like that:
#foreach( $userLanguages as $key => $userLanguageTitle)
<option value="{{$key}}">{{$userLanguageTitle}}</option>
#endforeach

How to convert and display the value from the database in laravel

I want do display outlet name as "Food" if the value in the database is "FC" and display "Express" if the value in the database is "EX" in my for each drop down.
Here's my controller
$outlet_name = StoreFC::select('loc_type')
->groupBy('loc_type')
->orderBy('loc_type', 'ASC')
->get();
$district_name = StoreFC::select('location')
->groupBy('location')
->orderBy('location', 'ASC')
->get();
return view('test.store-fc', compact('outlet_name','district_name'));
Here's my view
<div class="form-group">
<select name="filter_district" id="filter_district" class="form-control" required>
<option value="">Select Location</option>
#foreach ($district_name as $district)
<option value="{{ $district->location }}">{{ $district->location }}</option>
#endforeach
</select>
</div>
<div class="form-group">
<select name="filter_outlet" id="filter_outlet" class="form-control" required>
<option value="">Select Outlet</option>
#foreach($outlet_name as $outlet)
<option value="{{ $outlet->loc_type }}">{{ $outlet->loc_type }}</option>
#endforeach
</select>
</div>
Here's my model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class StoreFC extends Model
{
protected $table = 'store_foodcity';
}
This is how it show now in the drop down
You need to create custom getters in model StoreFC.
[https://laravel.com/docs/5.8/eloquent-mutators#defining-an-accessor][1]
The best thing U can do is to create a new column with the full name "Food" for "FX", otherwize.... you have to modify that mutator every time U change something in database.

Setting selected option in laravel from database

I have a problem here, I want to make an edit form, I want the province that appears in the edit form to be the province selected from the database, here my code
<select name="provinsi" id="provinsi" class="form-control">
<option value="">Pilih Provinsi</option>
#foreach ($province as $prov)
<option value="{{$prov->name}}">{{$prov->name}}</option>
#endforeach
</select>
here my controller code
public function ShowSantri(Request $request,$id)
{
$province = DB::table('provinces')->get();
$profiles = Profile::find($request->id);
return view('admin/modal/edit_santri',compact('profiles','province'));
You can try like this:
<select name="provinsi" id="provinsi" class="form-control">
<option value="">Pilih Provinsi</option>
#foreach ($province as $prov)
<option value="{{$prov->name}}"
#if ($profiles['provName'] == $prov->name)
selected
#endif>
{{$prov->name}}
</option>
#endforeach
</select>
Just I'm not sure what is name in your $profiles for province. But I think that is what you need.
Here and here are some examples.
Good luck!
Use or change this code based on your needs:
<option value="{{$prov->name}}" {{ $prov->name == $profiles->prov_id ? "selected" : "" }}>{{$prov->name}}</option>
I think the $prov->name should be $prov->id, if not, you can change $profiles->prov_id to $profiles->prov_name. It depends on your database structure.

Enable/disable the custom field when another custom field is selected

I need to disable one custom field when other custom field is selected. For example, I have an custom field with dropdown format. When i click on 2nd option of a particular custom field,the other custom field should be disabled and one more custom field should be enabled. How do i do that in redmine?
As I understood you wanted to change the option of 2nd dropdown box on bases of 1st dropdown's option selection:
This is sample code which perform the same using Jquery. You can modify it as per your requirement.
HTML
<select class="product" id="select_1" name="product">
<option selected="selected" value=""> Choose Category </option>
<option value="Mens Suits"> Mens Suits </option>
<option value="Womens Suit"> Womens Suits </option>
<option value="Children Suit"> Children Suits </option>
</select>
<select class="size" id="select_3" name="size">
<option selected="selected" value=""> Choose Size </option>
</select>
Jquery:
var men = '<option selected="selected" value=""> Choose Size </option><option value="36">36</option><option value="38">38</option><option value="40">40</option>';
var women = '<option selected="selected" value=""> Choose Size </option><option value="26">26</option><option value="28">28</option><option value="30">30</option>';
var children = '<option selected="selected" value=""> Choose Size </option><option value="12">12</option><option value="11">11</option><option value="10">10</option>';
$(document).ready(function(){
$("select#select_1").on('change',function(){
if($(this).val()=="Mens Suits"){
$("select#select_3").html(men);
}else if($(this).val()=="Womens Suit"){
$("select#select_3").html(women);
}else if($(this).val()=="Children Suit"){
$("select#select_3").html(children);
}
});
});
Working Demo
I hope this helps you. :)

Resources