在从表单存储数据时使用未定义的常量

时间:2017-02-03 09:33:11

标签: php laravel laravel-5.3 blade

我创建了一个模型

Review.php

和它的资源控制器

ReviewController.php

路线

Route::resource('review','ReviewController');

并创建了一个表单来获取值。我的店铺方法:

public function store(Request $request)
{

    $this->validate($request, [
        'fullname' => 'required|max:255',
        'email'    => 'required',
        'country'  => 'required',
        'tourname' => 'required', 
        'content'  => 'required'
        ]);

    $reviews = new Review;

    $reviews->name = $request->fullname;
    $reviews->email = $request->email;
    $reviews->country = $request->country;
    $reviews->content = $request->content;
    $reviews->tour_id = $request->tourname;

    if($request->hasFile('clidentpp')){
        $image = $request->file('clidentpp');
        $filename = time().'.'.$image->getClientOriginalName();
        $location = public_path('images/client_review'.$filename);
        Image::make($image)->resize(128, 128)->save($location);

        $reviews->path = $location;
    }
    $reviews->save();
    Session::flash('success','Thank you for your review !');
    return back()->withInput(['tab'=>'complete']);

}

我收到错误

Use of undefined constant reviews - assumed 'reviews'

指向第$reviews = new Review;行。我尝试将$reviews更改为$review,但仍然没有运气。Error screenshot here.

2 个答案:

答案 0 :(得分:0)

应为 $reviews = new Review();

答案 1 :(得分:0)

试试这个。

    $review[] = '';
    $review['name'] = $request->fullname;
    $review['email'] = $request->email;
     ...
    Review::create($review);