我有一张表:配置文件表有一个外键和主键。我想根据两个条件更新行。喜欢: where ( id == 1 and user == 'admin')
如何使用 eloquent 在更新查询中使用两个参数。
我想在页面加载时将数据库中的选定值显示到下拉列表中。
我的控制器索引功能是:
public function index()
{
$country_data =DB::table('country')->select('country_id','country_name')->get();
$profile_data= DB::table('profiles')->select('*')->where('id',$user_id)->first();
return view('profile_update',compact('profile_data','country_data'));
}
Run Code Online (Sandbox Code Playgroud)
数据库中高度的列名是 :Height
我在 profile_update.blade.php 的下拉菜单是
<select class="select4" name="country" id="country">
<option value="">Please Select</option>
@foreach($country_data as $country)
<option value="{{$country->country_id}}" {{$country_data->country == $country->country_id ? 'selected' : ''}}>{{$country->country_name}}</option>
@endforeach</select>
Run Code Online (Sandbox Code Playgroud) 我已将出生日期保存在 MySQL 数据库中。
table name : **users**
field name : **dob**
Run Code Online (Sandbox Code Playgroud)
现在我想在视图中显示年龄。我的查询是:
$user_info = DB::table('users')->select('(year(curdate())-year(dob)) as age')->get();
Run Code Online (Sandbox Code Playgroud)
我正在使用 Laravel 5.5。
但这正在造成错误。如何使用 Laravel 中的查询生成器计算年龄?
laravel ×3
dropdown ×1
eloquent ×1
laravel-5 ×1
laravel-5.5 ×1
mysql ×1
php ×1
select ×1
sql-update ×1