尝试阅读属性和“用户”在布尔
用户ID显示BOOL错误,我会通过使用删除从列表中删除的位置保留列表
我对Laravel 9有一个问题,每当我单击删除时, 模型
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Doctor_review extends Model
{
use HasFactory;
public $timestamps = false;
protected $primaryKey = 'doctorReviewID';
}
这是我的控制器部分
$reviews = Doctor_review::all();
return view('admin.docreviews')->with('doctor_reviews', $reviews);
}
public function deletereview(Request $request){
$review = Doctor_review::where('doctorReviewID', $request->doctorReviewID)->first();
return view('admin.docreviews')->with('doctor_reviews', $review);
}
public function deletereviewSubmit(Request $request){
$review = Doctor_review::where('doctorReviewID', $request->doctorReviewID)->first();
$review->delete();
return redirect()->route('docreviews');
}
}
,这是我的刀片页面
@extends('layouts.appAdmin')
@section('contentAdmin')
<table class = "table table-border">
<tr>
<th>Patient ID</th>
<th>Doctor ID</th>
<th>Description</th>
<th>Rating</th>
</tr>
@foreach($doctor_reviews as $review)
<tr>
<td>{{$review->userID}}</td>
<td>{{$review->doctorID}}</td>
<td>{{$review->description}}</td>
<td>{{$review->point}}</td>
<td><a href="/deletereview/{{$review->doctorReviewID}}">Delete</a></td>
</tr>
@endforeach
@endsection
,这是我的删除表单页面
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
<div class="container" style="width:500px;">
<h2>Delete review</h2>
<form action="{{ route('deletereview') }}" method="POST">
{{csrf_field()}}
<input type="hidden" name="doctorReviewID" value="{{review->doctorReviewID}}">
<div class="form-group">
<label for="userID">Patient ID</label>
<input type="text" class="form-control" id="userID" name="userID" placeholder="Enter Patient ID">
</div>
<div class="form-group">
<label for="doctorID">Doctor ID</label>
<input type="text" class="form-control" id="doctorID" name="doctorID" placeholder="Enter Doctor ID">
</div>
<div class="form-group">
<label for="description">Description</label>
<input type="text" class="form-control" id="description" name="description" placeholder="description">
</div>
<div class="form-group">
<label for="point">Rating</label>
<input type="text" class="form-control" id="point" name="point" placeholder="point">
</div>
<div class="form-group p-1">
<span>
<input type="submit" name="Delete" value="Delete" class="btn btn-info">
</span>
</div>
</div>
</form>
</div>
</body>
</html>
I have a problem with Laravel 9 where the userID is showing bool error whenever I click on the delete, I ma keeping a list from where by using delete I can delete from the list but Attempt to read property "userID" on bool
This is my model
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Doctor_review extends Model
{
use HasFactory;
public $timestamps = false;
protected $primaryKey = 'doctorReviewID';
}
This is my controller portion
$reviews = Doctor_review::all();
return view('admin.docreviews')->with('doctor_reviews', $reviews);
}
public function deletereview(Request $request){
$review = Doctor_review::where('doctorReviewID', $request->doctorReviewID)->first();
return view('admin.docreviews')->with('doctor_reviews', $review);
}
public function deletereviewSubmit(Request $request){
$review = Doctor_review::where('doctorReviewID', $request->doctorReviewID)->first();
$review->delete();
return redirect()->route('docreviews');
}
}
This is my blade page
@extends('layouts.appAdmin')
@section('contentAdmin')
<table class = "table table-border">
<tr>
<th>Patient ID</th>
<th>Doctor ID</th>
<th>Description</th>
<th>Rating</th>
</tr>
@foreach($doctor_reviews as $review)
<tr>
<td>{{$review->userID}}</td>
<td>{{$review->doctorID}}</td>
<td>{{$review->description}}</td>
<td>{{$review->point}}</td>
<td><a href="/deletereview/{{$review->doctorReviewID}}">Delete</a></td>
</tr>
@endforeach
@endsection
This is my delete form page
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
<div class="container" style="width:500px;">
<h2>Delete review</h2>
<form action="{{ route('deletereview') }}" method="POST">
{{csrf_field()}}
<input type="hidden" name="doctorReviewID" value="{{review->doctorReviewID}}">
<div class="form-group">
<label for="userID">Patient ID</label>
<input type="text" class="form-control" id="userID" name="userID" placeholder="Enter Patient ID">
</div>
<div class="form-group">
<label for="doctorID">Doctor ID</label>
<input type="text" class="form-control" id="doctorID" name="doctorID" placeholder="Enter Doctor ID">
</div>
<div class="form-group">
<label for="description">Description</label>
<input type="text" class="form-control" id="description" name="description" placeholder="description">
</div>
<div class="form-group">
<label for="point">Rating</label>
<input type="text" class="form-control" id="point" name="point" placeholder="point">
</div>
<div class="form-group p-1">
<span>
<input type="submit" name="Delete" value="Delete" class="btn btn-info">
</span>
</div>
</div>
</form>
</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想打电话给 - &gt;请确保您的用户ID不是布尔或无效。您可以在刀片中进行{{{dd($评论 - &gt; userId)}},以查看用户ID的值。
your userID value is boolean, if you want to call with -> please make sure your userID is not boolean or null. You can do {{ dd($review->userID) }} in your blade to see the value of userID.
没有完整的错误消息,我无法确定。但这是我的猜测:
这将为表格添加了评论列表,当您foreach时,您将循环浏览列表。
这将为表格添加单个评论,当您foreach时,您将循环浏览其属性。
可能会解决您的问题。但是我建议将刀片页面分配到列表查看页面和详细查看页面。
Without the full error message I can't really know for sure. But this is my guess:
This adds a list of reviews to the form, and when you foreach, you will loop through the list.
This will add a single review to the form, and when you foreach, you will loop through its properties.
Might fix your issue. But I'd suggest splitting the blade page into a list view page and a detail view page.
在两个函数中,您返回具有不同类型的变量的视图。
您正在使用 foreach循环读取两种类型的变量,即收集和单个值。
first()将返回元素本身,并且可以在刀片文件中为:
和 all()将返回a Collection 。
访问集合的数据 $评论在刀片文件循环中使用:
In two functions you are returning to one view with different type of variables.
You are using foreach loop to read the both type of variables i.e. collection and single value.
first() will return element itself and can be in blade file as:
And all() will return a Collection.
To access data of collection $review in blade file loop is used i.e.: