Sinres
2 months ago
129
1
Laravel

Calling other function in this same controller

Posted 2 months ago by Sinres

Hello Guys!

Look this is piece of my controller where a store a new record of sale. Where is the problem? I need use other function in function store in this same controller.

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $sale = new Sale;
        $sale->user_id = Auth::id();
        $sale->sale_number = $request->sale_number;
        $sale->customer_institution = $request->customer_institution;
        $sale->institution_address = $request->institution_address;
        $sale->product_name = $request->product_name;
        $sale->manufacturer = $sales->manufacturer;
        $sale->serial_number = $request->serial_number;
        $sale->amount_of_sale = $request->amount_of_sale;
        $sale->sale_date = $request->sale_date;
        $sale->term_realization = $request->term_realization;
        $sale->guarantee_period = $request->guarantee_period;
        $sale->directory_link = $request->directory_link;
        $sale->file_sale = $request->file_sale;
        $sale->sale_type = $request->sale_type;
        $sale->save();

        return $this->checkGuaranteePeriod($sale->guarantee_period);
    }

    /**
     * Checks the number of device inspection based on guarantee period.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function checkGuaranteePeriod($guarantee_period)
    {
        if ($guarantee_period == 60) {
            $number_of_inspection = 5;
        } elseif ($guarantee_period == 48) {
            $number_of_inspection = 4;
        } elseif ($guarantee_period == 36) {
            $number_of_inspection = 3;
        } elseif ($guarantee_period == 24) {
            $number_of_inspection = 2;
        } elseif ($guarantee_period == 12) {
            $number_of_inspection = 1;
        }
    }

My solution is good way for SOLID practice? I am asking for your understanding haha I'm at junior level

Please sign in or create an account to participate in this conversation.