<?php 

namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\model\Market_place; 
use View;
use Illuminate\Support\Facades\Input;
use App\Http\Requests\MarketplaceRequest;


class MarketplaceController extends Controller 
{
	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
            $market_places = Market_place::all(); 
            return View::make('pages.market_places')->with('market_places',$market_places);
	}

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
            return View::make('pages.new_market_place');
	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store(MarketplaceRequest $request)
	{
            $market_place = new Market_place();
            $market_place->name = Input::get('name');
            $market_place->commission = Input::get('commission');
            if($market_place->save())
            {                
                return redirect('market_places')->with('message', 'Market Place inserted Successfully.');            
            }
	}

	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
            $market_place_to_edit = Market_place::find($id);
            return View::make('pages.new_market_place')->with('market_place_to_edit',$market_place_to_edit);
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update()
	{
            $market_place_id = Input::get('market_place_id');  
            $market_place = Market_place::find($market_place_id);
            $market_place->name = Input::get('name');
            $market_place->commission = Input::get('commission');
            if($market_place->save())
            {                
                return redirect('market_places')->with('message','Market Place Updated Successfully.');            
            }
            else
            {
                return redirect('market_places')->with('message','Market Place Not Updated.');
            }
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
            //
	}
}
