Pass variable from the controller to several views in laravel

2

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
source

1 answer

2

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.

 <script>
 $scope.obtener= function($id){     
    $http.get(uploadUrl+"/"+$id)
    .then(function success(response){
        $scope.ficha= response.data;
        return $scope.ficha;
    });
    console.log($scope.checar);
};
</script>

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