mardi 2 octobre 2018

Use of undefined constant title - assumed 'title'

I am pretty new in Laravel,

actually I am trying to create a crud operation using Laravel 5.6, so I have created create, delete function successfully, but on update function I am getting an error

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)

Controller

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();
}

Model

class BlogCategories extends Model{
protected $fillable = ['title', 'slug', 'description', 'featured_image'];
protected $guarded = [];
}

Form

<form action="" 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="" 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="" 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="" 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="" 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>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire