First controller ViewData:
public function show(Request $request){
return $request->url;
}
Second controller where I want to pass value to the first controller's show method
use App\Http\Controllers\ViewData;
public function pass(){
$url = "https://abc.xyz"; // the value that i want to pass on first controller
$viewData= new ViewData;
$viewData->show(?);
}
How can I pass the data from the second controller's pass method to the first controller's show method?
CodePudding user response:
You need to create a new instance of Request.
public function pass(){
$url = "https://abc.xyz"; // the value that i want to pass on first controller
$viewData= new ViewData;
$content = new Request;
$content->url= $url;
$viewData->show($content);
}
Then in show method.
public function show(Request $request){
if($request->url)
{
return $request->url;
}
}
CodePudding user response:
It should work:
public function show(Request $request, $url = false){
if($url)
$request->merge(['url' => $url]);
return $request->url;
}
You may need to expect a parameter in the show method and update the relevant route.