我正在尝试迁移我的外键并以公司形式显示员工列表。:
1。我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', 'AdminCompaniesController',['as'=>'admin']);
Please Help me out
// this is how to send the variable to the view
public function index(){
$cat = Company::all();
return view('company/index', ['cat'=>$cat]);
}
@foreach ($cat as $row)
<option value="{{$row->id}}">{{$row->companyname}}</option>
@endforeach
return view('company/index')->with('cat', $cat);
你可以试试。去掉括号中的view
,去掉空格with('cat', $cat);
。