Laravel 6 Call controller method from another controller

Rate this post

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 :  10 Keys About Lunch Box With Ice Pack Compartment

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

Access your controller method
[php]
app(‘App\Http\Controllers\CricketerController’)->getScoreReport();
[/php]

[php]
app()->call(‘App\Http\Controllers\[email protected]’);
[/php]

Laravel controller method has parameters you can pass
[php]
app()->call(‘App\Http\Controllers\[email protected]’, [$team_id, $player_id]);
[/php]

Example 1: Use an external class in Controller
[php]
class CricketerClass {
public function getRuns() {
return [‘test’ => 50, ‘oneday’ => 100, ‘t20’ => 150];
}
}
[/php]

within \App folder

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

2. using Laravel Namespace within the file
[php]
namespace App\Classes;

class CricketerClass {
// …
[/php]

3.use in Laravel Controller
[php]
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’));
}

READ :  Laravel Eloquent Relationships Tutorial From Scratch

}
[/php]

Web Programming Tutorials Example with Demo

Read :

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.

Leave a Reply

Your email address will not be published.