我正在处理三个表,它们之间有两个数据透视表。它是一个与工作站具有多对多关系的工作簿,也是一个与客户端具有多对多关系的工作簿。现在我有一个页面,你可以在其中保存一个新的工作簿,你可以选择所有应该与它相关的工作站,也可以选择应该与该工作簿关联的客户端。我认为我只需要使用工作簿中的存储,因为那将是连接它们的表。
public function store(StoreWorkbookRequest $request)
{
$workbook = Workbook::create($request->only('wrkb_name'));
$workbook->stations()->sync($request->input('stations', []));
$workbook->clients()->sync($request->input('clients', []));
return redirect()->route('admin.workbooks.create')->with('success', 'Successfully Created a New Workbook');
}我也在使用livewire,并且我有在livewire组件中创建的表单。
<form action="{{route('admin.workbooks.store')}}" method="POST" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label for="">Workbook Name</label>
<input type="text" class="form-control" name="wrkb_name">
</div>
<table class="table-auto w-full mb-6">
<thead>
<tr>
<th class="px-4 py-2"></th>
@if($showRate)
<th wire:click="sortBy('SFM_rate')" style="cursor: pointer;" class="px-4 py-2">SFM Rate @include('partials.sort-icon',['field'=>'SFM_rate'])</th>
@endif
@if($showLetter)
<th wire:click="sortBy('call_letter')" style="cursor: pointer;" class="px-4 py-2">Call Letter @include('partials.sort-icon',['field'=>'call_letter'])</th>
@endif
</tr>
</thead>
<tbody>
@foreach($stations as $key => $station)
<tr>
<td class="border px-4 py-2">
<input wire:model="selected" value="{{ $station->id }}" type="checkbox">
</td>
@if($showRate)
<td class="border px-4 py-2">{{$station->SFM_rate}}</td>
@endif
@if($showLetter)
<td class="border px-4 py-2">{{$station->call_letter}}</td>
@endif
</tr>
@endforeach
</tbody>
</table>
{!! $stations->links() !!}
@else
<p class="text-center"> No stations were found</p>
@endif
<div class="w-full flex pb-10" >
<div class="w-1/6 relative mx-1">
<select wire:model="clientselected" class="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500" id="grid-state">
<option value="" >Select a Client</option>
@foreach($clients as $id => $client)
<option value="{{ $id }}">{{ $client->name }}</option>
@endforeach
</select>
</div>
<div class="w-1/6 relative mx-1 space-x-6">
<button class="block appearance-none w-full bg-black border border-gray-200 text-white py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500">Create Workbook</button>
</div>
</div>
</form>当我提交表单时,只创建了工作簿,两个数据透视表保持不变。
发布于 2021-07-16 04:02:38
我让它起作用了。我在选择器中添加了name="stations[]“和name="clients[]”
<input name="stations[]" wire:model="selected" value="{{ $station->id }}" type="checkbox"><select name="clients[]" wire:model="clientselected" class="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500" id="grid-state">现在,所有数据都在发送中。
https://stackoverflow.com/questions/68399387
复制相似问题