uccdev

uccdev

Member Since 1 Year Ago

Experience Points
7,680
Total
Experience

2,320 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
35
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 2
7,680 XP
Feb
19
3 days ago
Activity icon

Replied to Laravel CURL Project Works Fine On Local Machine - FAILS On Server?

Thank you for that. I tried both commands. To the curl --ipv4 -v "https://my.test.instructure.com/api/v1/accounts/1/admins?per_page=20" command, I got a full cURL log trace. Of the lines there, these two stood out:

HTTP/1.1 401 Unauthorized
...
"status":"unauthenticated","errors":[{"message":"user authorisation required"}

A check of my /etc/hosts file read like this:

 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
 143.239.2.37 buzzi buzzi.website.com

What exactly should be there instead?

Activity icon

Replied to Laravel CURL Project Works Fine On Local Machine - FAILS On Server?

cURL is definitely installed, curl -V works fine

@braunson curl_error($ch) gave me the following:

 Failed connect to my.test.instructure.com:443; Operation now in progress

From what I've read, it seems this is a timeout error?

I think it might be the program being behind a firewall. How can I check if it is?

Feb
18
4 days ago
Activity icon

Started a new Conversation Laravel CURL Project Works Fine On Local Machine - FAILS On Server?

I have a laravel project that makes a cURL request to a Canvas API endpoint. This project runs perfectly on my virtual machine. But on the centOS 7 server I've ported it to, its cURL requests don't work at all.

I get the following errors:

curl_getinfo($curl, CURLINFO_HTTP_CODE) returns curl error number 0. From what research I've done, this implies the server is refusing the connection

curl_exec($curl) returns false.

a dd of $curl or $resp dd($curl) returns a very empty string.

Below are some sample curl functions I use:

  //NOTE: $this->headers = ["Authorization: Bearer " . myServerAccessToken];
 //sets URL and $curl
 public function getAdmins() {
     $adminsURL = "https://my.test.instructure.com/api/v1/accounts/1/admins?per_page=20";
     $curl = curl_init();

     self::requestCurl($curl, $adminsURL, $this->headers);
     $resp = curl_exec($curl);
     dd($resp); //shows false
     return self::setHeaders($curl);
   }

  //something missing here?
 public function requestCurl($curl, $url, $headers) {
     return 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_CUSTOMREQUEST => 'GET',
       CURLOPT_HEADER => TRUE
     ]);
   }

 //returns "curl errno: 0"
 public function setHeaders($curl) {
     $resp = curl_exec($curl);
     $header_size = curl_getinfo( $curl, CURLINFO_HEADER_SIZE );
     $header = substr( $resp, 0, $header_size );
     $body = substr( $resp, $header_size); //$header_size
     $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     if (curl_getinfo($curl, CURLINFO_HTTP_CODE) != 200) {
       echo "<h3>Curl errno: " . curl_getinfo($curl, CURLINFO_HTTP_CODE) . "</h3>";
       dd($body); //EMPTY.
       return null;  //TODO error handling (I think returning null will be enough?)
     }
     $data = json_decode($body, true);
     return $data;
   }
    

Can anyone suggest why this might be happening, and what I could try to fix it? Any advice would be appreciated

Feb
14
1 week ago
Activity icon

Replied to Server Is Looking For Path "vendor/laravelcollective/html/src/helpers.php" Which Doesn't Seem To Exist?

Worked perfectly! The folder is there, and my server's running the site just fine now. Thank you!

Activity icon

Replied to Server Is Looking For Path "vendor/laravelcollective/html/src/helpers.php" Which Doesn't Seem To Exist?

no, it is apache apache. Over the vendor directory, permissions are drwxrwxr-x

Activity icon

Replied to Server Is Looking For Path "vendor/laravelcollective/html/src/helpers.php" Which Doesn't Seem To Exist?

I got the runtime error /var/www/MyProject/vendor/laravelcollective/html does not exist and could not be created

I gather this is a permissions issue, though I'm not sure which permissions to assign my non-root account to bypass this

Activity icon

Replied to Server Is Looking For Path "vendor/laravelcollective/html/src/helpers.php" Which Doesn't Seem To Exist?

I have two problems there, as I have two accounts. One does not have write permission over composer.json, but the other account is the root account, which the server warns me never to run composer commands from. What is the best approach to this, with that in mind?

Activity icon

Replied to Server Is Looking For Path "vendor/laravelcollective/html/src/helpers.php" Which Doesn't Seem To Exist?

I have not. Were you recommending that I call composer require laravelcollective/html on my server?

Activity icon

Replied to Server Is Looking For Path "vendor/laravelcollective/html/src/helpers.php" Which Doesn't Seem To Exist?

Sti3bas, I've run that command now successfully, and indeed, my computer version of the project has the vendor/laravelcollective/html/src folder path. I've git-pushed then pulled the project to my server version of it. However, I still do not see any vendor/laravelcollective folder path.

Has this happened before?

Activity icon

Replied to Server Is Looking For Path "vendor/laravelcollective/html/src/helpers.php" Which Doesn't Seem To Exist?

Thanks for the reply.

composer.json actually does have a laravelcollective value:

  "require": {
    "php": "^7.2",
    "fideloper/proxy": "^4.0",
    "guzzlehttp/guzzle": "^6.4",
    "laravel/framework": "^6.0",
    "laravel/passport": "^7.5",
    "laravel/tinker": "^1.0",
    "laravelcollective/html": "^6.0",
    "mtownsend/collection-xml": "^1.1",
    "mtownsend/request-xml": "^1.1",
    "mtownsend/response-xml": "^1.1"
  },

I just do not have a laravelcollective folder at all for it to point to. Having not touched this file in this project's lifetime, I can't say why.

Activity icon

Started a new Conversation Server Is Looking For Path "vendor/laravelcollective/html/src/helpers.php" Which Doesn't Seem To Exist?

I've uploaded my laravel project onto an apache server. It has an HTTP 500 error.

The logs say it's looking for the following:

 [php7:error] [pid 11339] [client 143.239.128.189:64623] PHP Fatal error:  require(): Failed opening required '/var/www/myProjectPath/vendor/composer/../laravelcollective/html/src/helpers.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/myProjectPath/vendor/composer/autoload_real.php on line 66``

Now, my project folder does have this path: vendor/laravelcollective/html/src/helpers.php But this is not the path that is being sought for: my project has no vendor/laravelcollective path, and yet one is being looked for.

Can anyone explain to me why it might be looking for this? I'd appreciate any insight

Feb
12
1 week ago
Activity icon

Started a new Conversation HTTP Error 500 On One Project On Server But Not The Other?

I've been uploading projects to a centos server lately. One of them is recognised, and shows me the main laravel index page.

The other is not recognised, and gives me a http 500 message.

I cannot check the logs of this page as its storage/logs folder on the server is empty.

I've checked the public directories of both and they seem to be effectively the same: they both have a css folder, a favicon.ico, a robots.txt file and an index.php file.

I change which directory the document root is pointing to. (e.g DocumentRoot = "/var/www/workingProject/public", vs DocumentRoot = "var/www/Err500Project/public")

Any advice on what I can do? I can provide more information on request, I'm just not sure what to look for

Jan
10
1 month ago
Activity icon

Started a new Conversation How To Make PHP Form Refer To A Value On The Same HTML Page?

In PHP Laravel, I have a page which deals with API endpoint data. Right now it paginates this data, which I've managed accordingly:

 <form action="courseList" method="get">
  <input type="hidden" name="pageNumber" value="2"> <!--where '2' is the next page''
  <input type="submit" name="Submit" value="Next Page">
 </form>'

This passes in a single pageNumber argument, which works fine for my URL routing:

Route::get('/c/courseList/{pageNumber}', '[email protected]')->name('courseList');

Which then starts with:

public function searchByCourse(Request $request) { ...

This gives $request a pageNumber value, and it works. That's great.

Now I want to be able to add a "Sort" value to $request. But the catch is that this value has to be defined outside of the form I'm using. It has to come from another HTML field in the page.

I'd like to put it in as a hidden value inside the form field I listed above, and have its value stored there. e.g:

 <input type="radio" name="myOtherInput" value="x">
 ...

 <form action="courseList" method="get">
     <input type="hidden" name="sort" value="nameOfHTMLFieldItem"> ...

I've tried researching this problem, but most results are about passing values from external pages, not dealing with the internal.

Is this possible? How might I do it?

Dec
10
2 months ago
Activity icon

Replied to "Call To Undefined Method" Of A Clearly Defined Method?

"I would argue that calling a controller method from another controller is bad practice. You should extract the logic to its own service class, or at least a trait."

Would it do to put the function inside of a Helper class, that both controllers use? That I might store in an App\Helpers directory?

Dec
09
2 months ago
Activity icon

Started a new Conversation "Call To Undefined Method" Of A Clearly Defined Method?

I have a class IndexController class with its own method verifyUser.

 public function verifyUser($user) {
     echo "Test!";
  }

Its actual code isn't as important as the nature that it isn't called when I want it to be.

It works perfectly fine in its base class, but when I try to call it in other classes I get different results:

   $this->indexController = new IndexController();
   $this->indexController->verifyUser(auth()->user());

I can confirm that auth()->user() is fine. The error message I get is something else: Call to undefined method: IndexController::verifyUser()

I can reword the call in a few different ways, such as:

 IndexController::verifyUser(auth()->user());

Or

 $thing = $this->indexController->verifyUser(auth()->user());

But it doesn't fit it.

I note that if I simply paste the code that verifyUser has into my new class, it works just fine. It's just this one form of method calling. I don't get why it works. Could anyone shed some light on why I might be getting this issue?

Dec
05
2 months ago
Activity icon

Replied to Is It Possible To Paginate Two Different Tables On The Same View?

I see, Snapey, thank you. What name exactly should I give them? Should the name match the div they are in? Or the name of the table they're referring to? Or the dataset, like courseData?

EDIT: I ask because I've modified my View with the following, where I put userData= value, and it unfortunately gave me a curl error:

  <?php //TODO Page Information. Configured for "v1/accounts/1/courses" endpoint, reconfigure to "v1/courses" endpoint
  //dd($cata);
  if (isset($uPageNums)) {
    ?><a href="<?php echo $uPageNums[0]; ?>" rel="<?php echo $uRels[0]; ?>"><?php echo $uRels[0]; ?></a>
    <?php
//      echo "<a href='" . $pageNum . "' rel='current'>Current</a>";
      if ($uPages[1] != null ) {
        ?> <a href="userData=<?php echo $uPageNums[1]; ?>" rel="<?php echo $uRels[1]; ?>"><?php echo $uRels[1]; ?></a>
      <?php
    } else { echo "Error"; }
      if ($uPages[2] != null) {
      ?>  <a href="userData=<?php echo $uPageNums[2]; ?>" rel="<?php echo $uRels[2]; ?>"><?php echo $uRels[2]; ?></a>
      <?php
      }
      if ($uPages[3] != null) {
        ?> <a href="userData=<?php echo $uPageNums[3]; ?>" rel="<?php echo $uRels[3]; ?>"><?php echo $uRels[3]; ?></a>
<?php }
  } else {
    echo "No user pageNums set!";
  }
Dec
04
2 months ago
Activity icon

Replied to Is It Possible To Paginate Two Different Tables On The Same View?

Thank you jl. I need to finish work now but I will give them another look in the morning.

Also, thanks, that makes me feel much better :D

Activity icon

Replied to Is It Possible To Paginate Two Different Tables On The Same View?

Also I've updated the original post. It now shows how I get the thread data. Just in case it's useful for understanding or giving feedback

Activity icon

Replied to Is It Possible To Paginate Two Different Tables On The Same View?

Thanks for your reply jlr. I am not using JS Ajax. I use PHP Laravel with custom functions to get the pagination links from my API endpoint. Then in the View, I use basic HTML in two separate divs to display the data.

EDIT: Thank you for the link. It seems to refer to Eloquent pagination in general, which is quite different to how I do it. As someone who's new to using Eloquent pagination, could you suggest how I might use it?

Activity icon

Started a new Conversation Is It Possible To Paginate Two Different Tables On The Same View?

So I have a laravel project that fetches data from not one, but two API endpoints. API endpoints like Canvas, so I cannot use any DB::table queries or other tricks. It gets the data from a Courses endpoint as well as a Users endpoint. I've been requested to fit the data of both tables on the same view.

Displaying all the data is fine, I'm able to collect the data from both tables in my controller and parse it to the view:

return view('index')
  ->with("courseData", $courseData) //course Data
  ->with("cPages", $cPages) //course pages
  ->with("cRels", $cRels) //course references 
  ->with("cPageNums", $pageNums) //course page numbers
  ->with("userData", $userData) //user data
  ->with("uPages", $uPages) //user pages
  ->with("uRels", $uRels) //user references
  ->with("uPageNums", $uPageNums); //user page numbers

I'm also able to successfully paginate the Courses table.

if (isset($cPageNums)) {
      ?><a href="<?php echo $cPageNums[0]; ?>" rel="<?php echo $cRels[0]; ?>"><?php echo $cRels[0]; ?></a>
      <?php
        if ($cPages[1] != null ) {
          ?> <a href="<?php echo $cPageNums[1]; ?>" rel="<?php echo $cRels[1]; ?>"><?php echo $cRels[1]; ?></a>
        <?php
      } else { echo "Error"; }
        if ($cPages[2] != null) {
        ?>  <a href="<?php echo $cPageNums[2]; ?>" rel="<?php echo $cRels[2]; ?>"><?php echo $cRels[2]; ?></a>
        <?php
        }
        if ($cPages[3] != null) {
          ?> <a href="<?php echo $cPageNums[3]; ?>" rel="<?php echo $cRels[3]; ?>"><?php echo $cRels[3]; ?></a>
  <?php }
    } else {
      echo "No course pageNums set!";
    }

For comparison's sake, my User pagination code, which is only different in that it uses different variables:

if (isset($uPageNums)) {
        ?><a href="<?php echo $uPageNums[0]; ?>" rel="<?php echo $uRels[0]; ?>"><?php echo $uRels[0]; ?></a>
        <?php
      if ($uPages[1] != null ) {
        ?> <a href="<?php echo $uPageNums[1]; ?>" rel="<?php echo $uRels[1]; ?>"><?php echo $uRels[1]; ?></a>
      <?php
    } else { echo "Error"; }
      if ($uPages[2] != null) {
      ?>  <a href="<?php echo $uPageNums[2]; ?>" rel="<?php echo $uRels[2]; ?>"><?php echo $uRels[2]; ?></a>
      <?php
      }
      if ($uPages[3] != null) {
        ?> <a href="<?php echo $uPageNums[3]; ?>" rel="<?php echo $uRels[3]; ?>"><?php echo $uRels[3]; ?></a>
<?php }
  } else {
    echo "No user pageNums set!";
  }
  ?>

So what happens when I click the buttons these create in my view? Well if they're the Course buttons, they work perfectly fine. I move between all the pages I need to.

When I click the user ones? I move through the Course table instead. It's as if the page only recognises the one set, not the other. So I suppose I've two big questions.

  1. Is what I'm looking to do possible? Paginate between two tables on the same webpage? I'm aware it might be easier to simply have a separate view for each, but management would prefer this way.

  2. If it is possible, what can I do to accomplish that? Or what is the mistake I'm presently making?

Any help on this matter would be greatly appreciated.

EDIT: For further clarity, here is how I sort pagination. Canvas naturally paginates its data, so I try to retrieve its links directly from that. Then after extraction, I pass the data containing those onto the view.

    $explData = explode("\n",$resp); //Need the page links in order to move from data to data, since Canvas keeps all its data paginatable.

    $courseLinks = self::getLinks($explData); //gets links from data
    if (is_null($links)) {
      echo "exec'd data did not contain any links";
      return null;
    }
    $cPageLinks = explode(",", $links); //the actual strings in full. Array form.
    $cPages = array_fill(0, 4, null); //the page URL links
    $cRels = array_fill(0, 4, null); //references (i.e "current", "next", "prev", "last")
    $cPageNums = array_fill(0, 4, null); //amount of pages
    $i = 0;
    //loop to populate the above
    foreach($cPageLinks as $p) {  //get the important page details and store them in these arrays
      $cPages[$i] = AppHelper::instance()->get_string_between($cPageLinks[$i], "<", ">"); //helper method, returns raw string.
      $cRels[$i] = AppHelper::instance()->get_string_between($cPageLinks[$i], 'rel="', '"');
      $cPageNums[$i] = AppHelper::instance()->get_string_between($cPageLinks[$i], "?page=", "&");
      $i++;
}

This process is mirrored for getting the User endpoint's pages.

Dec
02
2 months ago
Activity icon

Started a new Conversation Optimal Way To Pass User Name? (Based Off Data From Web Endpoint)

I'm implementing a search option which lets someone find a user from a webpage, depending on their name.

Look at this code here:

 public function searchByUser(Request $request) {
    $first = $request->firstname;
    $sur = $request->surname;
    $userURL = "https://my.website.com/?search_term=$first+$sur";

If someone were to type "Claire" for the firstname with no surname, it'd give me every user with "Claire" in the name, and the same rules for the surname, as well as combined together.

Now, this is functional, but I'm wondering three things:

  1. Is it optimal?
  2. At the moment I've had to split the name into two variables: what if I wanted to keep them in one? At the moment that doesn't work because my code can't interpret the split too well (e.g instead of "John%20Smith", it sees "John Smith", which gives me a broken result)
  3. Furthermore, what if someone wants a middle name, or has a more complex name to put in? e.g a middle name, like "John Jacob Smith" I suppose I can make a "middle_name" variable, but if there's another complication to the name, what then? Is there a one-size-fits-all for this sort of thing?

If anyone has any advice, that'd be helpful

EDIT: I should clarify, this is based on data from a webpage endpoint, so MySQL solutions will unfortunately not work.

Nov
28
2 months ago
Activity icon

Awarded Best Reply on ViewException: 'Trying To Get Property "id" Of Non-object'?

I tried it in PHP again with this code, and it worked.

  <div class="form-group">
      <table id="coursesTable" data-page-length='5' cellspacing="0"
class="table table-bordered table-striped table-hover table-condensed"
role="grid">
      <tr> <td>Hi</td></tr>

        <?php
        foreach($users as $u) {
          echo "<tr>";
          if (isset($u['id'])) {
            echo "<td>" . $u['id'] . "</td>"; //works
          } else { echo "<td>No course ID available</td>";
          }
          echo "</tr>";
        } ?>
      </table>
    </div>

I would like to be able to make this work with Blade, as it seems like it should be able to, but if it can't then I am content with a PHP-based solution

Activity icon

Replied to ViewException: 'Trying To Get Property "id" Of Non-object'?

I tried it in PHP again with this code, and it worked.

  <div class="form-group">
      <table id="coursesTable" data-page-length='5' cellspacing="0"
class="table table-bordered table-striped table-hover table-condensed"
role="grid">
      <tr> <td>Hi</td></tr>

        <?php
        foreach($users as $u) {
          echo "<tr>";
          if (isset($u['id'])) {
            echo "<td>" . $u['id'] . "</td>"; //works
          } else { echo "<td>No course ID available</td>";
          }
          echo "</tr>";
        } ?>
      </table>
    </div>

I would like to be able to make this work with Blade, as it seems like it should be able to, but if it can't then I am content with a PHP-based solution

Activity icon

Replied to ViewException: 'Trying To Get Property "id" Of Non-object'?

I've updated my original post with information about the array.

 array:9 [▼
   0 => array:12 [▼
     "id" => 111
     "name" => "my_user_name"
   ]
   1 => array:12 [▼
      "id" => 2222
      "name" => "my_other_user_name"
      ...
   ]
 ...
 ]

There are indeed null values in this multidimensional array, but I don't see how my present code doesn't account for those.

Activity icon

Replied to ViewException: 'Trying To Get Property "id" Of Non-object'?

I wish that were the case but it's not happening.

For one more full view of the table, here's the block of code:

 <table id="coursesTable" data-page-length='5' cellspacing="0"
class="table table-bordered table-striped table-hover table-condensed"
role="grid">
       @foreach($users as $u)
         {{ dd($u) }} <!--appears when not commented out-->
         <tr>
           <!--{{ dd($u) }} This gives a full array object, including an index "id" with a number value (e.g 10111) -->
           <td> {{ $u['id'] ?? 0 }} </td> <!--Shows neither the ID or 0. Empty.-->
           <td> {{ dd($u) }} </td> <!--Does not appear in any circumstance-->
         </tr>
       @endforeach
     </table>

Does blade have any complaints about echoing values in between HTML tags? I can't imagine what else could be the cause of these issues

Activity icon

Replied to ViewException: 'Trying To Get Property "id" Of Non-object'?

Sinnbeck, thank you for your reply.

Regretfully I have already tried the <td> {{ $u['id'] }} </td> approach, but it gives me only one of two results:

  1. An "undefined index 'id' error"
  2. A blank result. I know this to be an error because {{ dd($u) }} actually gives me a successful list of data - and indeed confirms there is an 'id' index.

The exact result of {{ dd($u) }} looks like so:

  array:44 [▼
    "id" => 11111
    "name" => "theName"
    "account_id" => 1
    "uuid" => "an ID"
    "start_at" => "2014-02-11T15:12:34Z"
    "is_public" => false
     .....
  ]
Activity icon

Started a new Conversation ViewException: 'Trying To Get Property "id" Of Non-object'?

I know this question has been asked several times before, but I've seen multiple threads on the matter and I can't get my head around it.

So I have this array called $users, an array of arrays with different fields in them. Namely the id field, which points to an integer. So as an example, ``$users[0]["id"] = 1111`.

I can confirm this is the case, as when I do a dd($users) then I get the correct values that I'm expecting. I can do the dd in either the controller or view and it works.

So I try to populate a simple HTML table with these values:

    <tr>
      @foreach($users as $u)
        <!--{{ dd($u) }} Gives a full array object successfully, including an index "id" with a number value (e.g 10111) -->
        <td> {{ $u->id }} </td> <!--This is the important line-->
      @endforeach
    </tr>

However, when I do this, I simply get an error instead:

ViewException: Trying to get property 'id' of non-object

I have looked up different questions that have had this issue. I've tried $u['id'] and instead just gotten the "undefined index" error. I've tried both versions in PHP instead of blade, and still get the same error. Regrettably I still have this same issue. Can anyone offer some thoughts on what to do here?

EDIT: In case anyone is curious what $users in full looks like, it's essentially like this:

 array:9 [▼
   0 => array:12 [▼
     "id" => 111
     "name" => "my_user_name"
   ]
   1 => array:12 [▼
      "id" => 2222
      "name" => "my_other_user_name"
      ...
   ]
 ...
 ]

There are null entries in there, but I don't see why a simple {{ $u['id'] ?? 0 }} doesn't account for those. It is indeed populated and being correctly passed over into my view: if my code is correct, then something should be appearing.

Nov
26
2 months ago
Activity icon

Replied to "500 Server Error" When Visiting Certain Pages?

Should have done this first. It pointed out a typo in my code. Thank you.

Activity icon

Started a new Conversation "500 Server Error" When Visiting Certain Pages?

My laravel login setup was working fine for me yesterday. When I log in today, I find I have the plain textNo input file specified. on my webpage.

That error is fixed when I run vagrant reload --provision. But when I do that, and access any of my normal routes that were working fine yesterday, I get this message instead:

 500 Server Error

I don't get why. From searching up past instances of this error, it's usually because of how homestead's public/index files are configured. But again, I have changed nothing since working on this yesterday, where it all worked fine.

I should note that two routes are an exception to this: the login route and the home route. These are both the laravel default package routes. However I need to access my main route, and that gives me the 500 Server Error issue.

Any advice wold be greatly appreciated.

Nov
25
2 months ago
Activity icon

Started a new Conversation Best Practice Question - One Route With Many Args, Or Several Arg-specific Routes?

I'm developing a web application right now, that shows values from a dataset of "users" and a dataset of "courses". There are essentially three base permutations that this can go, from what I see:

  1. The default result, which shows all the data available from the above indiscriminately
  2. Search for a user, and show the courses they're enrolled in
  3. Search for course, and show all the users enrolled in it

Performing these queries isn't a problem for me. But I'm of two minds on how to structure the controllers and views for such a thing. I think I can either:

  1. Write the one controller method for all three, giving it a different argument based on how it works.
  2. Write a different method for each, allowing specific actions. Can divide overlapping code up into different methods that each method calls on.

And the views:

  1. Write the one view for all three. Structured accordingly for variation in controller arguments.
  2. Write three views. One for each type of search.

I'm leaning towards 2) for the Controllers and 1) for the Views. But I'd appreciate other people's opinions on this before I have to fully commit to either. Any advice?

Nov
21
3 months ago
Activity icon

Replied to Check If User Is Logged In Or Not?

Of course it was something so simple. Thought I had, but hadn't. That function is no longer crashing the page. And I'm going to guess that it's also the best way to check, per block of code, that a user is still logged in. Thank you!

Also Nakov, if those two methods are so similar, can I ask why they both exist? Is there any situation I'd rather use one over the other?

Activity icon

Replied to Check If User Is Logged In Or Not?

I can try that now, but I can confirm that other pages work fine. Things like home and login work fine. It's this page, when I have this block of code, that's giving the oopsie.

I also use auth()->user() and commands like auth()->user()->email in the controller method, if it's of interest, and those have not caused complaint for a logged-in user

Activity icon

Started a new Conversation Check If User Is Logged In Or Not?

In my laravel controller, I'm running scripts that depend on the default laravel login/database setup. I want to check at the start of my [email protected]() call if the user is logged in or not. If so, resume as normal. If not, redirect him.

From research, the best way to do this seems to be Auth::check(). So I've put in the following code:

 if (Auth::check()) { //if the user is logged in
    echo "<h2>You are logged in. Continue!</h2>";
  } else {
    echo "<h2>I should redirect you somewhere else now.</h2>";
  }

However, this just gives me a 500 Server Error. Even when I put the above in a try-catch next, it still gives me this problem. In fact, it doesn't matter if I'm logged in or not: the page still gives this issue.

Why would this be happening? And if this isn't what I should do to check a user's logged-in status, what should I use?

Nov
20
3 months ago
Activity icon

Started a new Conversation How To Point To Homestead Database Outside Of The Virtual Machine?

I was suggested DBeaver as a tool to quickly check on database values I've been creating. However, it's asking for a full file path, e.g C:/Users/.../my_database_directory. In the case of Laravel and Homestead, what path exactly should I give here?

Activity icon

Replied to Laravel Confused About Where To Find Auth Files When I Call "php Artisan Route:list"?

I had actually forgotten to update the namespace in the Admin folder, my mistake. Thankfully that error is now fixed!

Activity icon

Replied to "npm Install && Npm Run Dev" But No Login/Register Controller?

Thank for your reply. By the authentication chapter, do you mean this link here? https://laracasts.com/series/laravel-from-scratch-2018/episodes/27

Nov
19
3 months ago
Activity icon

Started a new Conversation Laravel Confused About Where To Find Auth Files When I Call "php Artisan Route:list"?

I'm setting up my laravel project for login and registration. I've run the npm install dev && npm run dev and gotten all the required files. I have my relevant controllers like LoginController inside the App\Http\Controllers\Auth\LoginController directory (that part is important).

I've also set up a populated SQLite database, with an Admin model. So I try to run a simple php artisan route:list command.

And that's when I get this error:

 Target class App\Http\Controllers\Admin\Auth\LoginController] does not exist.

Now I do have a LoginController, but the App\Http\Controllers\Admin directory doesn't exist. So I create one, then I cut my Auth folder and paste it into the App\Http\Controllers\Admin point. Instead I get this error:

 ErrorException: include(/home/.../Controllers/Auth/LoginController.php): failed to open stream: No such file or directory``

So it needs both folders and directories to exist? Fine. I make a copy of the Auth folder in its original location. So now I have two Auth folders with the same controllers:

App\Http\Controllers\Admin\Auth App\Http\Controllers\Auth

And I run the route:list command again. What do I get?

 FatalErrorException: Cannot declare class App\Http\Controllers\Auth\LoginController, because the name is already in use.``

I seem to be trapped in a circle! Help?

Activity icon

Started a new Conversation "npm Install && Npm Run Dev" But No Login/Register Controller?

I'm setting up a login/registration DB system with laravel 6.x. I've run npm install && npm run dev as requested, and I've gotten a lot of things from it. I have all the views in my views/auth folder. I have package.json configured as expected in this video series here: https://laracasts.com/series/laravel-6-from-scratch/episodes/34

But what I don't have are the controllers. No controllers exist except for the ones I have. I don't know if I deleted them and forgot, or if they were never installed, but how do I get them back? Running npm install && npm run dev again hasn't restored them.

Bear in mind, I'm only asking for the template, out-of-the-box controllers here, but I'd rather not uninstall/reinstall my project if I can help it. If anyone has those on hand, or knows where I can get them, that'd be quite helpful.

Activity icon

Replied to Password As Word Variable: Can Laravel Make It Safe?

I've gotten the go-ahead for an SQLite database, thanks a bundle!

Although you've answered this thread's question, have you got any tips on where to start with configuring a laravel database for web apps? I admit, despite having some web and MySQL experience, this is my first time doing such a thing with laravel. The video you linked presumes the existence of an app/database folder, for instance, but i've gotten no such directory in my current project

EDIT: This tutorial video does a great job bringing me up to speed very quickly on it. https://www.youtube.com/watch?v=kWmnQvznkUI All it lacks is finer detail control like modifying existing database entries

Nov
18
3 months ago
Activity icon

Replied to Password As Word Variable: Can Laravel Make It Safe?

I'm using a homestead database, which to my immediate understanding is MySQL oriented. Or can I switch to SQLite in there?

Activity icon

Replied to Password As Word Variable: Can Laravel Make It Safe?

Thank you again. After reading the documentation (found that file while we you were replying) I'm wondering if this is compatible with my project goal:

Laravel includes a simple method of seeding your database with test data using seed classes...

I do not use a database, unfortunately. I would like to convince management to do so for this project, but they have other ideas they'd like to consider to avoid having to maintain a DB. I'm exploring my options as best I can at the moment.

Activity icon

Replied to Password As Word Variable: Can Laravel Make It Safe?

Would that .env var be the APP_DEBUG variable? I've set that to false now just in case I commit to that option.

I'm not sure what you mean by seeding. Could you go into more detail, please?

Activity icon

Replied to Password As Word Variable: Can Laravel Make It Safe?

@sinnbeck Thank you. I suspect it could be an .env variable, but the idea is that these passwords represent one of some two dozen special users. Given what I know of storing .env values, this is either impossible or impossible to do neatly and safely. Either we could do a "one password for all" system, or we put the passwords in some other file, like storage/somePasswordList.txt

@tray2 I'm inclined to agree, but it's not my decision to make ultimately. Still, as of today I've been able to extend it to file variables. That is, I'm being requested to create a file in some directory outside of the web root (e.g 'storage' directory). Essentially, not unlike the answer given here: https://security.stackexchange.com/questions/216636/is-storing-sensitive-data-in-files-instead-of-a-database-safe

Is this fine? I am not sure if this is fine still. Partly because I've not done encryption like this before, though it seems simple: my concerns are if it's optimal or not. If it can scratch concerns like keeping user sessions, or in authorising multiple users instead of just the one. Any more opinions on this would be very valuable.

Activity icon

Started a new Conversation Password As Word Variable: Can Laravel Make It Safe?

I've been asked to consider storing a password as an environment variable in order to log into an account, as opposed to a database login/password system that'd ask more to maintain. I've read elsewhere, in places such as this, that it isn't a recommended practice: https://stackoverflow.com/questions/12461484/is-it-secure-to-store-passwords-as-environment-variables-rather-than-as-plain-t

In short, it seems less than optimal. I'd appreciate some more opinions on the matter, if at all possible. And is there anything I can do in Laravel to make it more secure?

EDIT: I've been able to extend it to file variables. That is, I'm being requested to create a file in some directory outside of the web root (e.g 'storage' directory). Essentially, not unlike the answer given here: https://security.stackexchange.com/questions/216636/is-storing-sensitive-data-in-files-instead-of-a-database-safe

I am not sure if this is fine still. Partly because I've not done encryption like this before, though it seems simple: my concerns are if it's optimal or not. If it can scratch concerns like keeping user sessions, or in authorising multiple users instead of just the one. Any more opinions on this would be very valuable.

Activity icon

Replied to Is Passport Useful If I Already Have An API With OAuth2 Authentication?

It is helpful, thank you very much for replying. Documentation on this combination of software is sparse, so when some recommend it while I'm trying to use another element, I'm glad for clarity when I can find it.

Nov
15
3 months ago
Activity icon

Started a new Conversation Is Passport Useful If I Already Have An API With OAuth2 Authentication?

My current project requires me to use the Canvas API. https://canvas.instructure.com/doc/api/ This API has OAuth2 authentication, I have the means to create clients on it, and can make redirects using it.

Depending on if some person is logged in based on Canvas information, they're permitted onto the page they want, or redirected elsewhere.

Since I use Laravel, some have recommended Passport to me, but since Passport seems to be all about setting up an OAuth2 server, is it redundant if I already have one? Or is there some other end to which I might need it?

Nov
14
3 months ago
Activity icon

Started a new Conversation Laravel Passport OAuth2 Route - Goes To Login Page Instead?

I've followed the Passport configuration documentation here, as well as these tutorials: laravel.com/docs/6.x/passport

https://mattstauffer.com/blog/introducing-laravel-passport/

https://blog.shameerc.com/2016/08/set-up-oauth2-server-using-laravel-passport

In short, Passport is configured on my machine, and I've created many clients for what I understand to be my Passport-based OAuth2 server.

Now when I create my first route, to test this, it looks like so:

Route::get('/hi', function() {
  // Build the query parameter string to pass auth information to our request
  $query = http_build_query([
        'client_id' => '10',
        'redirect_uri' => 'https://192.168.10.10/callback',
        'response_type' => 'code',
        'scope' => 'conference'
    ]);

    // Redirect the user to the OAuth authorization page
    return redirect('https://192.168.10.10/oauth/authorize?' . $query);
});

This is meant to point to an authorisation page generated by Passport, which then takes me to my callback route below:

Route::get('/callback', function (Request $request) {
    $state = $request->session()->pull('state');

    throw_unless(
        strlen($state) > 0 && $state === $request->state,
        InvalidArgumentException::class
    );

    $http = new GuzzleHttp\Client;
    $response = $http->post('http://ucc.test.instrucutre.com/login/oauth2/auth?', [
        'headers' => [
          'Accept' => 'application/json',
        ],
        'form_params' => [
            'grant_type' => 'authorization_code',
            'client_id' => '10', //'12',
            'client_secret' => 'PUnRnNg30GVcIYKiRRwtPpCIiVb8FBYZft5iBYqx',
            'redirect_uri' => '192.168.10.10/callback',
            'code' => '', //$request->code,
        ],
    ]);
    return json_decode((string) $response->getBody(), true)['access_token'];
});

However, I never get to see this. Instead I am taken straight to my login page, 192.168.10.10/login

Why does it take me here? I don't see this step in any of the tutorials I've read or questions I've read up on.

Activity icon

Started a new Conversation Laravel Passport: $request After Redirect Is Null?

I'm trying to set up OAuth2 authorisation between my Canvas API and my Laravel Passport routing. Here is my laravel routing so far;

 Route::get('/hi', function() {
   // Build the query parameter string to pass auth information to our request
   $query = http_build_query([
         'client_id' => 'my_canvas_dev_key',
         'redirect_uri' => 'https://192.168.10.10/callback',
         'response_type' => 'code',
         'scope' => 'conference'
     ]);
     // Redirect the user to the OAuth authorization page
     return redirect('https://my.test.instructure.com/login/oauth2/auth?' . $query);
 });

This route works. It passes me onto the Canvas authorisation page, which shows buttons asking me for permission. After being granted it, then redirects me to the 'callback' route below:

 Route::get('/callback', function (Request $request) {
     $state = $request->session()->pull('state');
     echo "<h2>In callback. State is " . $state . "</h2>"; //for testing
     throw_unless(
         strlen($state) > 0 && $state === $request->state,
         InvalidArgumentException::class
     );

     $http = new GuzzleHttp\Client;
     $response = $http->post('http://my.test.instrucutre.com/login/oauth2/auth?', [
         'headers' => [
           'Accept' => 'application/json',
         ],
         'form_params' => [
             'grant_type' => 'authorization_code',
             'client_id' => '12',
             'client_secret' => '0RRYBR86IBlkrAGnYzw6MTfMgCiSdzaAMkhhEsZ7',
             'redirect_uri' => 'http://www.startpage.com', //for testing
             'code' => $request->code,
         ],
     ]);
     return json_decode((string) $response->getBody(), true);
 });

This does not work. $request is null, as a dd($request) reveals at any point in this function. I don't understand why. Can anyone offer some suggestions why?

These are samples of tutorials for this step that I've read: https://mattstauffer.com/blog/introducing-laravel-passport/ https://laravel.com/docs/6.x/passport https://blog.shameerc.com/2016/08/set-up-oauth2-server-using-laravel-passport