<commit_before><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
use App\Entity;
use App\Review;

use App\Http\Requests;

class ReviewsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $user = User::where('email',$request->input('user_email'))->first();
        $entity = Entity::where('pretty_url', $request->input('pretty_url'))->first();
        $old_review = Review::where(['entity_id' => $entity['id'], 'user_id' => $user['id']]);
        if(count($old_review) === 0 ){
            $new_review = new Review;
            $new_review['user_id'] = $user['id'];
            $new_review['entity_id'] = $entity['id'];
            $new_review['score'] = $request->input('score');
            $new_review->save();
            $resp['code'] = 1;
            $resp['message'] = 'Initial review submitted successfully';
        } else {
            $old_review->update(['score' => $request->input('score')]);
            $resp['code'] = 1;
            $resp['message'] = 'Review update submitted successfully';
        }
        
        //we still need to double-check to see if a user has already submitted a score
        
        return $resp;<commit_msg>Fix reviews create / update function by adding ->get() to end of query<commit_after><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
use App\Entity;
use App\Review;
use App\Criteria;

use App\Http\Requests;

class ReviewsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $new_review = [];
        $old_review = [];
        $user = User::where('email',$request->input('user_email'))->first();
        $entity = Entity::where('pretty_url', $request->input('pretty_url'))->first();
        $criteria = Criteria::where('name', $request->input('criteria'))->first();
        $old_review = Review::where(['entity_id' => $entity['id'], 'user_id' => $user['id'], 'criteria_id' => $criteria['id']])->get();
        if(count($old_review) === 0 ){
            $new_review = new Review;
            $new_review['user_id'] = $user['id'];
            $new_review['entity_id'] = $entity['id'];
            $new_review['score'] = $request->input('score');
            $new_review['criteria_id'] = $criteria['id'];
            $new_review->save();
            $resp['code'] = 1;
            $resp['message'] = 'Initial review submitted successfully';       
        } else {
            $old_review->update(['score' => $request->input('score')]);
            $resp['code'] = 1;
            $resp['message'] = 'Review update submitted successfully';

        }
        
        //we still need to double-check to see if a user has already submitted a score
        $resp['old_review'] = $old_review;
        $resp['new_review'] = $new_review;     
        $resp['count'] = count($old_review);
        return $resp;
{'fraction_non_alphanumeric': 0.1610738255033557, 'fraction_numerical': 0.0015487867836861124, 'mean_word_length': 2.2838983050847457, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5822462', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1133, 'n_words': 253}