我正在尝试迁移我的外键并以公司形式显示员工列表。为了那个原因:
1.My CompaniesController
public function index(){
$cat = Company::all();
return view(view:'company/index')->with ('cat', $cat);
}
这是我的公司迁移节目:
public function up() { Schema::create('company', function (Blueprint $table) { $table->id(); $table->unsignedBigInteger('emp_id'); $table->foreign('emp_id')->references('id')->on('employeee')->onUpdate('cascade')->onDelete('cascade'); $table->string('companyname')->nullable(); $table->string('connumber')->nullable(); $table->string('addressline1')->nullable(); $table->string('addressline2')->nullable(); $table->string('contactnumber')->nullable(); $table->string('suburb')->nullable(); $table->string('state')->nullable(); $table->string('postcode')->nullable(); $table->string('image'); $table->timestamps(); });
}
这是我的下拉菜单代码
`<div class="col-md-6">
<select name="">
@foreach ($cat as $row )
<option value="{{$row->id}}">{{$row->companyname}}</option>
@endforeach
</select>
</div>`
这是公司的管理路线:
Route::resource('/admin/companies', 'Admin\CompaniesController',['as'=>'admin']);
`
请帮帮我