Pass variable from the controller to several views in laravel


I have the following funcion edit in my controller

public function edit($id){
        $ficha= Data::findOrFail($id);
        return view('ficha.edit')->with('ficha', $ficha);

This sends the variable $ficha to 'ficha.edit', but I would like to know how to send the value of the variable $ficha to other views of my project from the same function.

asked by Darwin Gomez 29.11.2017 в 20:54

1 answer


You can modify your controller function in the following way:

public function edit($id){
        $ficha= Data::findOrFail($id);
        return $ficha;

And in the view in your script you send it to be called by a get request.

 $scope.obtener= function($id){     
    .then(function success(response){
        return $scope.ficha;

In this case I'm using angular, but you can do something similar with jquery or just javascript. And just send the function to call to load the data. I hope to solve your doubt.

answered by 29.11.2017 в 21:05