我需要在laravel中将数据输入select标签,我使用html标签在laravel中显示数据。
我有公司和分公司,我需要选择一家公司并在公司下键入分支,所以我需要列出公司并选择一个公司,但它显示错误变量compnaies未找到,请帮我解决这个问题
控制器
<?php
namespace App\Http\Controllers;
use App\Branch;
use App\Company;
use Illuminate\Http\Request;
class BranchController extends Controller
{
public function index()
{
$companies=Company::where('status','0')
->get();
return view('branch.index',['Company'=>$companies]);
return view('branch.index');
}
public function create()
{
}
public function store(Request $request)
{
$branch =Branch::create([
'name' =>$request->input('name'),
'comp_id' =>$request->input('comp_id'),
'dlr_id' =>$request->input('dlr_id'),
]);
if($branch){
return redirect()->with('success','Branch Created Successfully');
}
return back()->withInput()->with('error','Error Creating New Branch');
}
public function show(Branch $branch)
{
//
}
public function edit(Branch $branch)
{
//
}
public function update(Request $request, Branch $branch)
{
//
}
public function destroy(Branch $branch)
{
//
}
}
index.blade.php
div class="page-content-wrapper ">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div class="page-title-box">
<div class="btn-group float-right">
</div>
<h4 class="page-title">Branch Management</h4>
</div>
</div>
</div>
<!-- end page title end breadcrumb -->
<div class="row">
<div class="col-12">
<div class="card m-b-30">
<div class="card-body">
<h4 class="mt-0 header-title">Branch</h4>
<br>
<br>
<form method="post" action="{{route('branch.store')}}">
{{csrf_field()}}
<div class="form-group row">
<label class="col-sm-2 col-form-label">Company</label>
<div class="col-sm-10">
<select class="form-control" id="compnay" name="compnay">
<option>Select Company</option>
@foreach($companies as $companies)
<option value="{{$companies->comp_id}}">{{$companies->name}}</option>
@endforeach
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">Dealership</label>
<div class="col-sm-10">
<select class="form-control" id="dealer" name=" dealer">
<option>Select Dealer</option>
<option></option>
</select>
</div>
</div>
<div class="form-group row">
<label for="example-text-input" class="col-sm-2 col-form-label">Branch Name</label>
<div class="col-sm-10">
<input class="form-control" type="text" id="branch" required>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="page-title-box">
<div class="btn-group float-right">
<button class="btn btn-primary" type="submit">Button</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>