小编use*_*est的帖子

用于选择下拉列表的 Laravel 模型绑定

我希望在编辑表单中选择选择下拉值。

在我的控制器中

public function edit($id)
{
    $vedit = DB::table('vehicles')->where('id', $id)->first();
    $cartype= DB::table('car_category')->pluck('cartype'); 
    return view('vehicles.edit', compact('vedit','cartype'));
}
Run Code Online (Sandbox Code Playgroud)

视野中

{{ Form::label('Vehicle Type', 'Vehicle Type') }}
<select name="vehicle_type" class="form-control">
  @foreach($cartype as $cartypes)   
  <option value="{{ $cartypes}}">{{ $cartypes}}</option>
  @endforeach
</select>
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现这个目标?

php laravel-5

5
推荐指数
1
解决办法
4170
查看次数

如何在 Laravel 中选择外键值

我有两张表,一张是car_category有字段 - id,type。另一个名为车辆的表 具有字段 - c_id(FK 指汽车- id)。现在我想显示汽车类型的 FK(c_id) 值。我在模型中有以下代码,

class Car extends Model
{
    protected $guarded = [];
    protected $table = 'car_category';

    public function vehicles()
    {
        return $this->hasMany('Vehicle');
    }
}
Run Code Online (Sandbox Code Playgroud)

车辆型号,

class Vehicle extends Model
{
    protected $guarded = [];
    protected $table = 'vehicles';
    public function cars()
    {
        return $this->belongsTo('Car');
    }
}
Run Code Online (Sandbox Code Playgroud)

我对此有何疑问?我试过这段代码,结果错误。

$vehicles = "SELECT cars.cartype,vehicles.model FROM cars,vehicles 
             WHERE cars.id = vehicles.c_id";
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?有谁能够帮助我?

php mysql laravel-5

2
推荐指数
1
解决办法
1万
查看次数

Codeigniter 致命错误:session_start():无法初始化存储模块:path\to\Session\Session.php 中的用户(路径:C:\to\tmp)

当我要安装我的新 codeigniter 项目时。我得到了错误

致命错误:session_start(): 无法初始化存储模块:用户(路径:C:\xampp\tmp)在 C:\xampp\htdocs\Tetavendor\system\libraries\Session\Session.php on line 140

我在 stackoverflow PHP 7 用户会话问题中发现了类似的
问题 - Failed to initialize storage module

但是没有一个解决方案对我有用。我的 codeigniter 版本是 3.0.0。那么如何解决这个问题呢?

php codeigniter

0
推荐指数
1
解决办法
2万
查看次数

标签 统计

php ×3

laravel-5 ×2

codeigniter ×1

mysql ×1