[英]Updating and delete data in Laravel
我收到语法错误,
意外的“{”(视图:C:\\xampp\\htdocs\\sherukh\\resources\\views\\student\\index.blade.php)
我不知道我的语法错误在哪里我一直检查我没有发现任何错误并且我的删除查询也不起作用是否有任何位置错误因为当我按下删除按钮时它会将我带到错误的页面
@foreach($students as $row)
<tr>
<td>{{$row['first_name']}}</td>
<td>{{$row['last_name']}}</td>
<td><a href=" url('student/edit/'.$row['id'])"class="btn btn-warning">Edit</a></td>
<td>
<form method="post" class="delete_form" action="{{ action('StudentController@destroy/'.{{$row['id']}} )}}">
{{csrf_field()}}
<input type="hidden" name="_method" value="DELETE" />
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
错误在您的表单操作中:将其更改为,
<form method="post" class="delete_form" action="{{ url('student/'.$row['id']) }}">
您已经使用了 {{ }},因此如果您想使用任何变量,则无需再次使用。
从操作属性中删除“打开和结束内部大括号 {{”。用您的代码替换下面的代码。
@foreach($students as $row)
<tr>
<td>{{$row['first_name']}}</td>
<td>{{$row['last_name']}}</td>
<td><a href=" url('student/edit/'.$row['id'])"class="btn btn-warning">Edit</a></td>
<td>
<form method="post" class="delete_form" action="{{ action('StudentController@destroy/'. $row['id'] )}}">
{{csrf_field()}}
<input type="hidden" name="_method" value="DELETE" />
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
//blade
<form method="POST" action="{{ route('admin.tag.update',$tag->id) }}">
@csrf
@method('PUT')
<div class="form-group form-float">
<div class="form-line">
<input value="{{ old('name') }}{{ $tag->name }}" name="name" type="text" class="form-control">
<label class="form-label">{{ __('Name') }}</label>
</div>
</div>
<br>
<a href="{{ route('admin.tag.index') }}" class="btn btn-danger m-t-15 waves-effect">{{ __('BACK') }}</a>
<button type="submit" class="btn btn-primary m-t-15 waves-effect">{{ __('SUBMIT') }}</button>
</form>
//controller
public function edit($id)
{
$tag = Tag::find($id);
return view('admin.tag.edit',compact('tag'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$this->validate($request,[
'name' => 'required'
]);
$tag = Tag::find($id);
$tag->name = $request->name;
$tag->slug = str_slug($request->name);
$tag->save();
Toastr::success('Tag Successfully Updated','Success');
return redirect()->route('admin.tag.index');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.