Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

uccdev's avatar

Laravel Controller is not returning to view?

My problem is simple. On the latest version of laravel, my controller function is not returning to the given view. here is all I have.

my controller's function:

       public function findBBDirect($pageNumber) {
           $token = $this->accessToken;
           $headers = ['Authorization: Bearer ' . $token];

           $curl = curl_init();
           $validReturn = true;
           $url = "https://my.url.com"

             curl_setopt_array($curl, [
               CURLOPT_RETURNTRANSFER => TRUE,
               CURLINFO_HEADER_OUT => TRUE,
               CURLOPT_URL => $url,
               CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
               CURLOPT_SSL_VERIFYPEER => TRUE,
               CURLOPT_HTTPHEADER => $headers,
               CURLOPT_HEADER => TRUE,
               CURLOPT_RETURNTRANSFER, TRUE
             ]);
             if (curl_errno($curl)) {
               echo 'Error:' . curl_error($curl) . "<br>";
             } else { echo " all good<br>"; }
             $resp = curl_exec($curl);

             $header_size = curl_getinfo( $curl, CURLINFO_HEADER_SIZE );
             $header = substr( $resp, 0, $header_size );
             $body = substr( $resp, $header_size );

             $data = json_decode($body, true);

             $explData = explode("\n",$resp);
             $buttons = ["Current", "Next", "Prev", "First"];
             $links = $explData[15];
             $pageLinks = explode(",", $links);
             $pages = array_fill(0, 4, null); //the page URL links
             $rels = array_fill(0, 4, null); //references (i.e "current", "next", "prev", "last")
             $pageNums = array_fill(0, 4, null); //amount of pages
             $i = 0;

             foreach($pageLinks as $p) {
               $pages[$i] = AppHelper::instance()->get_string_between($pageLinks[$i], "<", ">");
               $rels[$i] = AppHelper::instance()->get_string_between($pageLinks[$i], 'rel="', '"');
               $pageNums[$i] = AppHelper::instance()->get_string_between($pageLinks[$i], "?page=", "&");
               $i++;
             }

             if (array_key_exists("errors", $data)) {
               $validReturn = false;
               echo "Invalid page found.</br>";
             }
             else {
               foreach ($data as $d) {
                 if((array_key_exists("id", $d)) && (self::hasBBDirect($d["id"]))) {
                   echo "Matching folder FOUND in course " . $d["id"] . "</br>";
                 } else {
                   echo "No matching folder found in course " . $d["id"] . "<br>";
                 }
               }
             }
             curl_close($curl);
             echo "<h4>Going to view Folder</h4>"; //THE LAST line reached
       
             return view('folder')
                 ->with("data", $data)
                 ->with("rels", $rels)
                 ->with("pages", $pages)
                 ->with("pageNums", $pageNums);
             echo "<h4>Didn't go?</h4>";
         }

And my view, "folder.blade.php":

       <html>
    <head>
        <title>Placeholder</title>
    </head>
    <body>
        <h1>Hi</h1>
    </body>
       </html>
       
       

Why do I never get to the view? The code gets to the "return" call, and stops. What's wrong?

0 likes
7 replies
Snapey's avatar

Did you get to this function direct from a route or by some other method?

is your 'Going to view Folder' shown?

uccdev's avatar

@SNAPEY - Yes to both, Snapey/ "Going to view Folder" appears, though that is the last bit of display to appear.

I got to function "findBBDirect" out of a route direct, yes. To be precise:

                     Route::get('/folder', 'FolderController@findFolderPageNum')
Snapey's avatar

I got to function "findBBDirect" out of a route direct, yes. To be precise:

Route::get('/folder', 'FolderController@findFolderPageNum')

Well that route goes to findFolderPageNum() method. So the answer is NO. You did not get to this function direct.

What does findFolderPageNum look like?

jlrdw's avatar

Have you tried changing:

public function findBBDirect($pageNumber) {

to

public function findFolderPageNum($pageNumber) {

Where are you passing $pageNumber, I must have over looked something.

Snapey's avatar
Snapey
Best Answer
Level 122

As you have not replied and I'm about to go to bed, I'll guess at your problem.

You call controller function findFolderPageNum...

public function findFolderPageNum()
{

    // do some stuff

    // do more stuff

    $something = $this->findBBDirect($stuff);

    // bit more stuff

    return;
}

public function findBBDirect($things)
{

    // yada yada

             echo "<h4>Going to view Folder</h4>"; //THE LAST line reached
       
             return view('folder')
                 ->with("data", $data)
                 ->with("rels", $rels)
                 ->with("pages", $pages)
                 ->with("pageNums", $pageNums);
             echo "<h4>Didn't go?</h4>";
}

1st observation <h4>Didn't go?</h4> will never happen because this is dead code as it appears AFTER the return statement.

2nd observation You call findBBDirect. It returns a view, but you don't do anything with it. and simply return from the controller.

You need to either

return $this->findBBDirect($stuff);

or save what it returns and then return this. for example, I captured the return in $something.

then you can do other things then

return $something;
2 likes
jlrdw's avatar

Reply if you do get it working.

1 like
uccdev's avatar

@SNAPEY - Snapey, sorry for the delay, we're on different timezones and I was well out of the office at this point. Indeed, my findFolderPageNum was using self::findBBDirect($thing) But after changing it to: return $this->findBBDirect($stuff); The view is being returned at long last. Things are now all working as they should be. Thank you!

Please or to participate in this conversation.