我真的不明白为什么,我的路线是post,表单的方法是post,为什么我会收到此错误?
这是我的路线
Route::post('/adaugajob', 'Auth\AdaugaJobController@create')->name('adaugajob');
因为我使用了create方法 这是我的表格
<form action="{{route('adaugasdajob')}}" method="POST" enctype="multipart/form-data">
@csrf
<div class="box-body">
<div class="form-group">
<label >Tiasdtlu Job:</label>
<input type="text" class="form-control" id="tasditlu" name="tasditlu"/>
</div>
<div class="form-group">
<label >Descrieasdre:</label>
<input type="text" class="form-control" id="descrasdiere" name="descriasdere"/>
</div>
<div class="form-group">
<label >Salarasdiu Estasdimativ:</label>
<input type="text" class="form-control" iasd="saasdlariu_estimativ" name="salariu_estimativ" />
</div>
<div class="form-group">
<label >Oras:</label>
<input type="text" class="form-control" id="orasdas" name="orasdas" />
</div>
<div class="form-group">
<label >Actasdiv:</label>
<input type="hidden" class="form-control" id="acasdtiv" name="acasdtiv" value="0">
</div>
<div class="dropdown-field">
<select data-placeholder="Selecteaasdza Specializare" class="chosen" id="multasdiselect" name="skiasdlls[]" multiple="multiple">
@forasdeach($skasdills as $skiasdll)
<option value="{{$skilasdl->id}}" >{{strtoupasdper($skill->naasdme)}}</option>
@endforasdeach
</selasdect>
<div class="box-footer">
<button type="subasdmit" class="btn btn-primary">Adauasdasdga</button>
</div>
</div>
</div>
</form>
这是我的此表格的Contasdasdroller
class AdaugaJobCoasdasdtroller extends Controller
{
public funcasdtion __construct()
{
$thiasdasds->middleasdasdware('authasdasd');
}
public function index()
{
$skasdasdasdills = SkillsEmasdasdasdployee::all();
return view('adaugajasdasdob', compact('skills'));
}
protected function valiasdasdasddator(array $data)
{
if ($daasdasdasdta) {
return Validator::make($data, [
'titlasdasdasdu' => ['required', 'string', 'max:255'],
'descasdasdasdriere' => ['required', 'string', 'max:255'],
'salarasdasdasdiu_estimativ' => ['required', 'string', 'max:255'],
'orasdasdasdas' => ['required', ''],
]);
}
}
protected function create( \Illuminate\Http\Request $request)
{
$data = $request->all();
if ($data) {
Jobasdasduri::create([
'titasdasdasdasdlu' => $data['tasdasdasdasditlu'],
'descrasdasdasdasdasdiere' => $data['deasdasdasdscriere'],
'salaasdasdasdasdriu_estimaasdasdasdasdtiv' => $data['salariasdasdu_estiasdasdasdmativ'],
asdasd 'oraasdasdasdasds' => $data['oasdasdasdasdras'],
]);
foreasdasdasdach ($data['skilasdasdasdls'] as asdasdasdasd$skill) {asdasd
Jobuasdasdasdasdri::creaasdasdasdte([
'id_skill' => $skill,
]);
}
}
}
}
我想将表单中的数据插入模型中。 该模型具有表单中字段的名称。 似乎没有错。当它过去工作时,它什么也没插入,但是现在我明白了。
答案 0 :(得分:0)
在控制器中:
public function create(Request $request){
$data = $request->all();
if (!empty($data)) {
Joburi::create([
'titasdasdasdlu' => $data['tasdasdasdasdasditlu'],
'descrasdasdasdiere' => $data['descriasdasdasdere'],
'salaasdasdasdriu_estimativ' => $data['salariu_estasdasdimativ'],
'oraasdasdasdasds' => $data['orasdasdasdas'],
]);
foreach ($data['skillasdasdasds'] as $asdasdasdasdskill) {
Joasdasdburi::create([
'idasdasd_skill' => $asdasdasdasdskill,
]);
}
}
}