[英]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.