<commit_before><?php

namespace App\Http\Controllers\Manager;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Timegridio\Concierge\Models\Business;
use Timegridio\Concierge\Models\Service;

class BusinessServiceController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index(Business $business)
    {
        logger()->info(__METHOD__);
        logger()->info(sprintf('businessId:%s', $business->id));

        $this->authorize('manageServices', $business);

        // BEGIN

        return view('manager.businesses.services.index', compact('business'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create(Business $business)
    {
        logger()->info(__METHOD__);
        logger()->info(sprintf('businessId:%s', $business->id));

        $this->authorize('manageServices', $business);

        // BEGIN

        $types = $business->servicetypes->pluck('name', 'id');

        $service = new Service([
            'duration' => $business->pref('service_default_duration'),
        ]); // For Form Model Binding
        return view('manager.businesses.services.create', compact('business', 'service', 'types'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store(Business $business, Request $request)
    {
        logger()->info(__METHOD__);
        logger()->info(sprintf('businessId:%s', $business->id));

        $this->authorize('manageServices', $business);

        // BEGIN

        //////////////////
        // FOR REFACTOR //
        //////////////////

        $service = Service::firstOrNew($request->except('_token'));

        $service->business()->associate($business->id);

        if ($request->get('type_id')) {
            $service->type()->associate($request->get('type_id'));
        }

        $service->save();

        logger()->info("Stored serviceId:{$service->id}");

        flash()->success(trans('manager.service.msg.store.success'));

        return redirect()->route('manager.business.service.index', [$business]);
    }

    /**<commit_msg>Redirect to Service show page after creation by default<commit_after><?php

namespace App\Http\Controllers\Manager;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Timegridio\Concierge\Models\Business;
use Timegridio\Concierge\Models\Service;

class BusinessServiceController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index(Business $business)
    {
        logger()->info(__METHOD__);
        logger()->info(sprintf('businessId:%s', $business->id));

        $this->authorize('manageServices', $business);

        // BEGIN

        return view('manager.businesses.services.index', compact('business'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create(Business $business)
    {
        logger()->info(__METHOD__);
        logger()->info(sprintf('businessId:%s', $business->id));

        $this->authorize('manageServices', $business);

        // BEGIN

        $types = $business->servicetypes->pluck('name', 'id');

        $service = new Service([
            'duration' => $business->pref('service_default_duration'),
        ]); // For Form Model Binding
        return view('manager.businesses.services.create', compact('business', 'service', 'types'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store(Business $business, Request $request)
    {
        logger()->info(__METHOD__);
        logger()->info(sprintf('businessId:%s', $business->id));

        $this->authorize('manageServices', $business);

        // BEGIN

        //////////////////
        // FOR REFACTOR //
        //////////////////

        $service = Service::firstOrNew($request->except('_token'));

        $service->business()->associate($business->id);

        if ($request->get('type_id')) {
            $service->type()->associate($request->get('type_id'));
        }

        $service->save();

        logger()->info("Stored serviceId:{$service->id}");

        flash()->success(trans('manager.service.msg.store.success'));

        return redirect()->route('manager.business.service.show', [$business, $service]);
    }

    /**
{'fraction_non_alphanumeric': 0.17596471885336273, 'fraction_numerical': 0.0, 'mean_word_length': 2.5054095826893352, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, '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': '4937269', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1203, 'n_words': 227}