Laravel 6 Call controller method from another controller

Today, We want to share with you Laravel 6 Call controller method from another controller.In this post we will show you wordpress plugin require another plugin, hear for Laravel 6 how to call a function from another controller we will give you demo and example for implement.In this post, we will learn about How do I call a controller function from another controller in laravel 6? with an example.

Laravel 6 Call controller method from another controller

There are the Following The simple About Access Controller method from another controller in Laravel 6 Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to call model function from another model in Laravel 6?, so the laravel call controller method from another method is used for this example is following below.

READ :  Vue Shopping Cart Example - Vuejs Shopping Cart | Shopping Cart Application

How to use external classes and PHP files in Laravel 6 Controller?

Access your controller method

app('App\Http\Controllers\CricketerController')->getScoreReport();

app()->call('App\Http\Controllers\[email protected]');

Laravel controller method has parameters you can pass

app()->call('App\Http\Controllers\[email protected]', [$team_id, $player_id]);

E-junkie: Sell digital downloads online

E-junkie Provides a Copy-paste buy-now, and cart buttons for selling downloads, codes and tangible products on any website, blog, social media, email and messenger!

Also see:

  1. The Top 10+ Best Webinar Software Platforms For 2020-2021
  2. Build Your Future Godaddy Careers And Jobs
  3. Introduction To Web Hosting Services

Example 1: Use an external class in Controller

class CricketerClass {
  public function getRuns() {
    return ['test' => 50, 'oneday' => 100, 't20' => 150];
  }
}

within \App folder

make a separate one – like App\Libraries, App\Classes or App\Services

2. using Laravel Namespace within the file

namespace App\Classes;

class CricketerClass {
// ...

3.use in Laravel Controller

namespace App\Http\Controllers;

use App\Classes\CricketerClass;

class DetailsController extends Controller
{
  /**
   * Display homepage.
   *
   * @return Response
   */
  public function getHome()
  {
    $cricketerClass = new CricketerClass();
    $runs = $cricketerClass->getRuns();
    return view('cricketer.details', compact('runs'));
  }

}

Web Programming Tutorials Example with Demo

Read :

READ :  Vuejs Custom Filters -date currency array-objects vuejs filter

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about how to use one controller method in another controller laravel.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.