Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save farukyildiz/a408823cb5c237347cf7f390b79a3ec1 to your computer and use it in GitHub Desktop.
Save farukyildiz/a408823cb5c237347cf7f390b79a3ec1 to your computer and use it in GitHub Desktop.
Call Controller Function From Another Controller (Laravel Framework)
/* **************************************************** */
/* ***************** First Controller ***************** */
/* **************************************************** */
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class FunctionController extends Controller
{
public function CallThisFunction($String){
echo $String;
}
}
trait PassData_CallThisFunction {
public function PassData($String) {
parent::CallThisFunction($String);
}
}
?>
/* ***************************************************** */
/* ***************** Second Controller ***************** */
/* ***************************************************** */
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Cms\Helper\FunctionController;
class CallClass extends FunctionController {
use PassData;
}
class FromThisController extends Controller
{
public function Index(){
$FunctionController = new CallClass();
$ReturnString = $FunctionController->PassData('Data...');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment