Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm using pluck to retrieve some columns (name & id) and populate on form select. This is my current solution
Controller
$shops = DB::table('shops')->pluck('shop_name', 'id');
return View::make('index')->with('shops', $shops)
View
{{ Form::select('id', $shops, null, ['class' => 'form-control']) }}
Output
<select class="form-control" name="id">
<option value="1">JDon</option>
<option value="2">Watsons</option>
</select>
How about if I want to retrieve 3 columns (name, address & id) and I want to show to the user the shop name & address?
Try this :
$shops = DB::table('shops')
->select(DB::raw("CONCAT(shop_name,' ',address) AS shop_full_name"),'id')
->pluck('shop_full_name', 'id');
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
Function From Customer to Order & Function check active order
Query
How to get customers where doesnt have relation in Order Models and customers where have relation in Order but the Order was inactive ??
Get Customer where doesnt have relation in order and customer where have relation in Order but Order state was inactive/expired
Try This
Customer::with('orders')->whereDoesntHave('orders')->orWhereHas('orders', function($query){
$query->select('orders.state')
->from('orders')
->whereColumn('orders.customer_id', 'customers.id');
}, 'expired')->get();
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a courses table and every course has many sessions,
So I need to sort courses by the first session of the course date for Laravel Project.
this way you can set a method in Course model to get the oldest Session model(which means first session):
public function oldestSession()
{
return $this->hasOne(Session::class)->oldestOfMany();
}
and then you may simply query your course model by adding constraints on that method :
$courses = Course::with(['oldestSession' => function ($query) {
$query->orderBy('created_at', 'desc');
}])->get();
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Im trying to make a feature called "Edit Profile User" this
so in this feature im as Admin that can Edit User's Profile such as Name, username , DOB, etc.
in this feature we also can edit/Assign Product to this user. Example
User A have product :
1. Shampoo
2. Soap
3. Toothpick
and in server we've more than 3 product which are : Shampoo, Soap, Toothpick, Sponge, and Towel (5 items)
so the problem is : how to show the items that User have and automatically selected in select option, and also show the product that user didnt have / still available in server ?
so the example is :
User A Product :
1. Shampoo (selected)
2. Soap (selected)
3. Toothpick (selected)
4. Sponge
5. Towel
im still confuse and no idea , already a week searching on google .
and i use Chosen from harvest with multiple select
here's the source : https://harvesthq.github.io/chosen/
can anybody help me figure it out this problem ? im so stressed
*and this project based in Laravel
<form action="process.php" method="POST">
<select name="items[]" class="form-control">
<option value="Ketchup" selected>Ketchup</option>
<option value="Mustard">Mustard</option>
</select>
<input type="submit" value="submit">
</form>
Then in process.php
$items = $_POST['items'];
foreach ($items as $item) {
echo '$item' . <br>;
}
This will show the items you've selected
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a table in database that is TEXT field. In this table i have stored my product ids . Now when i go to cart and get all product id of cart i want to match from database field and get only those ids that there stored in product id.
Please see image first.
In this field you will see "check_values" field. here all product ids are stored in comma separated.
Let me take a example
Like i have purchase a product that product id is 161. So i want to match 161 id from "check_value" filed and get only those ids (from images) that having 161.(11,14,15).
Hope you understand my question.
You can use FIND_IN_SET e.g.
SELECT * FROM images WHERE FIND_IN_SET(161, check_values) > 0
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i'm trying to create dropdown menu, this drop down menu is about name of countries, so when the user for example choose country A then all the posts that are associated with country A will be displayed.
So my question is do i need to create a separate PHP file for every country in order to get the posts that are associated to a particular country?
No you would create your dropdown as usual with
<select name="myCountry">
<option>Country A</option>
<option>Country B</option>
<option>etc lol</option>
</select>
Then have your form point to your PHP processing file, and in there you would do something like.
$selectedCounty = $_GET['myCountry']; //This assigns the selected value from that country dropdown into a usable variable.
Then u query the database.
Lets assume you have a database table called "countries" and a column with the countries listed called "myCountries".
$selectCountryQS = SELECT * FROM countries WHERE myCountries = '$selectedCountry';
Then put it into action
$selectCountryDoIt = mysqli_query('connection variable here', $selectCountryQS ) or die('error mssg'. mysqli_error(conection var here));
Then set a while loop that will grab ALL the posts data that you wanted.
while($row = mysqli_fetch_array($selectCountryDoIt)){
echo $row[' your column data to display here'];
}
This will give you what you need.
Hope this helps. Good luck