<commit_before><?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Auth;
use App\Article;
use Request;
use App\Offer;

class OffersController extends Controller {


	public function __construct(){
		$this->middleware('authUser');
		$this->middleware('csrf', ['only' => ['store', 'destroy', 'update']]);
	}

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		//
	}

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create($id)
	{
		$article= Article::find($id);

		if (!$article->isCurrentOwner())
		{
			return view('offers.create')
				->with('article', $article);
		}
		return redirect()
				->route('articles.show', ['id'=> $article->id]);
				

	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store($id)
	{
		$data = Request::all();
		$data['article_id'] = $id;		
		$data['user_id'] = Auth::user()->id;

		$validator = Offer::validate($data);

		if ( $validator->fails() )
		{
			return redirect()
				->back()
				->withInput()
				->with('errors', $validator->messages());
		}

		$article = Article::find($id);
		
		if ( (Auth::user()->id == $article->user_id) || (Auth::user()->alreadyOffered($id)) )<commit_msg>Se aregló bug cuando usuario ya ha ofertado en una subasta no pueda volver a ofertar sobre la misma.<commit_after><?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Auth;
use App\Article;
use Request;
use App\Offer;

class OffersController extends Controller {


	public function __construct(){
		$this->middleware('authUser');
		$this->middleware('csrf', ['only' => ['store', 'destroy', 'update']]);
	}

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		//
	}

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create($id)
	{
		$article= Article::find($id);

		if (!$article->isCurrentOwner() && !Auth::user()->alreadyOffered($id))
		{
			return view('offers.create')
				->with('article', $article);
		}
		return redirect()
				->route('articles.show', ['id'=> $article->id])
				->with('error', 'Usted ya ha ofertado sobre este artículo.');
				
	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store($id)
	{
		$data = Request::all();
		$data['article_id'] = $id;		
		$data['user_id'] = Auth::user()->id;

		$validator = Offer::validate($data);

		if ( $validator->fails() )
		{
			return redirect()
				->back()
				->withInput()
				->with('errors', $validator->messages());
		}

		$article = Article::find($id);
		
		if ( (Auth::user()->id == $article->user_id) || (Auth::user()->alreadyOffered($id)) )
{'fraction_non_alphanumeric': 0.19072708113804004, 'fraction_numerical': 0.0, 'mean_word_length': 3.5641025641025643, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '7311659', 'n_tokens_mistral': 1060, 'n_tokens_neox': 934, 'n_words': 225}