title: How to call other function from the same controller in Laravel application?
body: <p>I'm very new to Laravel and I was given a Laravel project, where I need to add some new features. The person, who has previously worked on that project hadn't left even a single comment in the code and now I must make my own scenarios about the features.
  I have a controller, defined with some functions (dashboard, show_project, save_project etc.) and in one of my function, I need to use the result of calling other function. </p>
  
  <p>In the concrete example, the call is made from "<a href="http://127.0.0.1:8000/username/project_slug" rel="nofollow noreferrer">http://127.0.0.1:8000/username/project_slug</a>" - there is a button "Save" and post function, called on <em>onClick</em> event. The function, whose output I need is normally called on "<a href="http://127.0.0.1:8000/username/project_slug/svg" rel="nofollow noreferrer">http://127.0.0.1:8000/username/project_slug/svg</a>", which returns a view. </p>
  
  <p>For better understanding, there's an example of the flow:<br>
  The user wants to save his/her project (an UML diagram) but in order to have a thumbnail, a function which generates a view (SVG format) will be called and the idea is, to take the HTML content of the page, which is on "<a href="http://127.0.0.1:8000/username/project_slug/svg" rel="nofollow noreferrer">http://127.0.0.1:8000/username/project_slug/svg</a>" and to pass it to another API in order an image to be generated. </p>
  
  <p>So far, I tried with <strong>cURL</strong>, <strong>file_get_contents</strong>, <strong>file_get_html</strong>, <strong>render</strong> methods but when I return the output, the server just keeps waiting and shows no error messages. </p>
  
  <pre><code>//The both functions are in ProjectController.php
  
  /**
   * A function, for saving the json file, where the whole of the diagram 
   * components are described. From the frontend we receive the project_id and  
   * the project_data(the json content).
   */
  public function save_project(Request $request) {
          $input = $request-&gt;only(['project_id', 'project_data']);
  
          /*
            Here we need to call the other function, to render the HTML content
            and to pass it to the other API. Then we save the result with the
            other information.
          */
  
          /*
            What I've tried?
            $new_link = 'http://' . $_SERVER['HTTP_HOST'] . "/$username" 
                                                ."/$project_slug" . "/svg";
            $contents = file_get_contents($new_link);
            return $contents;
          */
  
          //In the same way with cURL.
  
          $project = Project::where('user_id',session('userid'))
                            -&gt;where('id',$input['project_id'])-&gt;first();
          $project-&gt;project_data = json_encode($input['project_data']);
          if($project-&gt;save()) {
              return ["status"=&gt;"saved"];
          }
          else {
              return ["status"=&gt;"error"];
          }
      }
  
  /**
   * A function, which takes the the Json content (project_data) from the 
   * database and passes it to the view, where the Json is transformed in HTML 
   * tags. 
   */
  public function generate_svg(Request $request,$username,$project_slug) {
          if(session('username')!=$username) {
              return redirect("/");
          }
  
          $userid = session('userid');
  
          $project = Project::where([
              'user_id' =&gt; $userid,
              'slug' =&gt; $project_slug,
          ])-&gt;first();
  
          if(!is_null($project)) {
              return view('svg',compact('project'));        
          }
      }
  
  </code></pre>
  
  <p>I've read about some possible ways, including Guzzle request but maybe I haven't understood correctly the idea: </p>
  
  <p>If I need to make a <strong>Guzzle</strong> request from my controller to the other function inside my controller, do I need an API configuration?</p>
  
  <p>What I mean? Example:
  Before saving the project, the user is on this URL address "<a href="http://127.0.0.1:8000/hristo/16test" rel="nofollow noreferrer">http://127.0.0.1:8000/hristo/16test</a>". Inside the controller, I have in session variables the token, the username(hristo) and i can get the project_name(16test) from the URL but after passing this URL to the <strong>generate_svg</strong> function, there is no indication of error or success. </p>
  
  <p>So I'm missing some kind of token information?</p>