1

I've been getting the error Creating default object from empty value laravelI was successful to insert new rows with the following code but today when I tried testing the code it is returning the error pointing on the line $reviw->rating = $request->productrating;.

Structure of my db table is:

id|fname|lname|email|country|title|content|rating|thumbnail|tour_id|status

    public function store(Request $request)
{
    // dd($request->all());
    $this->validate($request, [
        'fname'     => 'required',
        'lname'     =>  'required',
        'email'     => 'required',
        'country'   => 'required',
        'title'   => 'required|min:10',
        'productrating' => 'required',
        'content'   => 'required|min:10'
        ]);        
    // dd($request->productrating);
    $review = new Review;
    $review->fname = $request->fname;
    $review->lname = $request->lname;
    $review->email = $request->email;
    $review->country = $request->country;
    $review->title = $request->title;
    $review->content = $request->content;        
    $reviw->rating = $request->productrating;
    if($request->hasFile('fileupload1')){
        $image = $request->file('fileupload1');
        $filename = 'thumb'.time().'.'.$image->getClientOriginalExtension();
        $location = 'images/client_review/'.$filename;
        Image::make($image)->resize(200, 200)->save($location);
        $review->thumbnail = $location;
    }
    $review->tour_id = $request->product_id;
    $review->status = false;
    $review->save();
    Session::flash('success','Thank You for submitting us your review.');
    return view('public.pages.message-review');        
}

I'm sending following data from the form to save into the table.enter image description here

2 Answers 2

2

I think you need to update your code like :

    $review = new Review;
    $review->fname = $request->fname;
    $review->lname = $request->lname;
    $review->email = $request->email;
    $review->country = $request->country;
    $review->title = $request->title;
    $review->content = $request->content;        
    $review->rating = $request->productrating;
Sign up to request clarification or add additional context in comments.

Comments

1

You have an error in $reviw->rating = $request->productrating; change $reviw to $review and it will work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.