Debug School

rakesh kumar
rakesh kumar

Posted on

Laravel:how-to-call- another function-from-same-controller-in-laravel

how-to-call-function-from-same-controller-in-laravel
how-to-call-function-from-same-controller-in-laravel
how-to-use-attempt-in-laravel

First Method

  $colorCode = $this->getColorCode('red');
Enter fullscreen mode Exit fullscreen mode

Second Method

$printReport = new PrintReportController;

$prinReport->getPrintReport();

Enter fullscreen mode Exit fullscreen mode

Full Code

 public function index(Request $request)
    {
        $colorCode = $this->getColorCode('red');

        $post = Post::create([
            'name' => 'Silver',
            'stock' => 100,
            'bg_color' => $colorCode
        ]);

        dd($post);
    }

    /**
     * Write code on Method
     *
     * @return response()
     */
    pivate function getColorCode($colorName)
    {
        $colors = [
            'pink' => '#FFC0CB',
            'plum' => '#DDA0DD',
            'powderblue' => '#B0E0E6',
            'purple' => '#800080',
            'red' => '#FF0000',
        ];

        return $colors[$colorName];
    }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)