我在Laravel中很陌生,
实际上,我正在尝试使用Laravel 5.6创建一个crud操作,所以我已经成功创建了create,delete函数,但是在update函数上却出现了错误
Please find the attched image for detailed error
Use of undefined constant title - assumed 'title' (this will throw an Error in a future version of PHP)
控制器
public function edit($id){
$blogCategories = BlogCategories::find($id);
if (empty($blogCategories)) {
Flash::error('Category not found');
return redirect(route('categories.index'));
}
return view('cms/BlogCategories/editCategory')->with('blogCategories', $blogCategories);
}
public function update(Request $request, $id){
$blogCategories = BlogCategories::find($id);
$blogCategories->title = $request->get(title);
$blogCategories->slug = $request->get(slug);
$blogCategories->description = $request->get(description);
$blogCategories->featured_image = $request->get(featured_image);
$blogCategories->save();
return redirect()->back();
}
模型
class BlogCategories extends Model{
protected $fillable = ['title', 'slug', 'description', 'featured_image'];
protected $guarded = [];
}
表格
<form action="{{route('categories.update', $blogCategories->id)}}" method="post" class="m-form m-form--fit m-form--label-align-right">
@csrf
@method('put')
<div class="m-portlet__body">
<div class="form-group m-form__group">
<label>Title</label>
<input type="text" class="form-control m-input" name="title" id="title" value="{{$blogCategories->title}}" aria-describedby="emailHelp" placeholder="Muhammad Owais">
</div>
<div class="form-group m-form__group">
<label>slug</label>
<input type="text" class="form-control m-input" name="slug" id="slug" value="{{$blogCategories->slug}}" aria-describedby="emailHelp" placeholder="mail@domain.com">
</div>
<div class="form-group m-form__group">
<label>Description</label>
<textarea class="form-control" name="description" id="description" value="{{$blogCategories->description}}" placeholder="Enter Description"></textarea>
</div>
<div class="form-group m-form__group">
<label>Featured Image</label>
<input type="text" class="form-control m-input" name="featured_image" id="featured_image" value="{{$blogCategories->featured_image}}" aria-describedby="emailHelp" placeholder="Enter Amazon S3 URL">
</div>
</div>
<div class="m-portlet__foot m-portlet__foot--fit">
<div class="m-form__actions">
<button type="submit" class="btn btn-primary">
Submit
</button>
<button type="reset" class="btn btn-secondary">
Cancel
</button>
</div>
</div>
</form>
答案 0 :(得分:1)
对所有HTTP请求使用引号,例如:
$request->get('title');
$request->get('slug');