uccdev

uccdev

Member Since 1 Year Ago

Experience Points
5,390
Total
Experience

4,610 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
33
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
5,390 XP
14 Aug
1 month ago

uccdev left a reply on Email Data Not Appearing In View?

This worked perfectly, thank you Snapey!

13 Aug
1 month ago

uccdev left a reply on Email Data Not Appearing In View?

Aura, thank you very much. It took some tweaking but I've added a CustomMail class to my project. However, I still have a problem: while I'm receiving the emails, the data still isn't appearing in the view!

I call it inside my main file's function like so:

         Mail::to("[email protected]")
          ->send(new CustomMail($data));

Which I've defined like this:

           class CustomMail extends Mailable
           {
               use Queueable, SerializesModels;

               protected $data;   
       
               public function __construct($myData)
               {
                   $this->data = $myData;
               }

              public function build()
              {
                   return $this->from("[email protected]")
                   ->with($this->data)
                   ->view('emails.numbers_found');
              }
          }

It may be worth noting that a Log::info call from build() proves that $this->dataproves the data has made it to the build() function just fine. I'm thinking the issue is either with how I use the return call from build(), or how my view works (which is the same as in the original post). Any idea why the data would be null in the view when using this method?

uccdev started a new conversation Email Data Not Appearing In View?

I have a simple email function that wants to send a view with data. The data is a simple numeric array: at present it has two values, as a simple Log::info confirms:

  (
      [0] => 53
      [1] => 117
  )

So I pass that through an email function:

//$data is the array above
Mail::send('emails.numbers_found', $data, function($message) {
          $message->to('[email protected]');
          $message->from('[email protected]');
});

And it sends that information off to this view:

  <p>Your numbers are as follows.</p>
  <ul>
      <li>test hi</li>
      @isset($data)
        @foreach($data as $b)
          <li>$b</li>
        @endforeach
      @endisset
      <li>test bye</li>
  </ul>

I receive the email like I expect, but for some reason, $data doesn't appear. Instead I only see: "Your numbers are as follows: -test hi -test bye

I don't see how $data could possibly be null once it's reached the view, and yet, nothing is appearing. Why? Does anyone have any understanding why this might be happening? Any help would be greatly appreciated.

12 Aug
1 month ago

uccdev left a reply on Laravel: Email Is Sent, But Not Received?

I think I've made just that confusion, @erikverbeek My mistake. I'd like to test it by emailing a real address: do you have any recommended emailing tools for just that, which work with laravel?

09 Aug
1 month ago

uccdev left a reply on Laravel: Email Is Sent, But Not Received?

But I'm not using a google app or any gmail accounts in these exchanges. "[email protected]" is referencing a work email, not a google email

uccdev left a reply on Laravel: Email Is Sent, But Not Received?

Interesting, thank you. I'm testing on both my local computer and on a server. Where can I adjust those settings?

uccdev left a reply on Laravel: Email Is Sent, But Not Received?

Apologies, Aura, I wasn't sure how to post images on here. https://imgur.com/27jR2na

The email shows the mailtrap.io account I've configured with "[email protected]" (which is also my outlook address). As you can see, it sending an email to "[email protected]" by the hour

However, when I check [email protected] for the corresponding email, it doesn't exist. I can't show a screenshot of there, but it gets no message at all, in either inbox or junk, at least not with the email I keep sending it. And yet, there's my mailtrap.io, clearly containing the message I'm sending.

Is this any clearer? Have I crossed my wires in configuration somewhere?

08 Aug
1 month ago

uccdev left a reply on Laravel: Email Is Sent, But Not Received?

I should have included this earlier, but I have this implemented already:

         MAIL_DRIVER=smtp
         MAIL_HOST=smtp.mailtrap.io
         MAIL_PORT=2525
         MAIL_USERNAME=my_username
         MAIL_PASSWORD=my_password
         [email protected]
         MAIL_FROM_NAME=Anon
         MAIL_ENCRYPTION=null

And I'm confused how I can't be sending mail to mailtrap if, when I log into my mailtrap inbox, I can see the inbox with my email message, and the from-to addresses included?

Is there anything this is missing?

uccdev started a new conversation Laravel: Email Is Sent, But Not Received?

So I have this function to send an email:

         public function email($data) {
               Mail::raw("Simple email to confirm email functionality works", function($message) {
                 $message->to('[email protected]');
                 $message->from('[email protected]');
               });
               if (count(Mail::failures()) > 0) {
                 Log::info("Error! Email did not send.");
               }
               Log::info("email sent");
         }

    .....
    self::email($data);
    ....

My config/mail.php is configured like so:

    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'port' => env('MAIL_PORT', xxx),
    'from' => [
            'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
            'name' => env('MAIL_FROM_NAME', 'me'),
    ],
            ....

So I expect my mailtrap account, when the function is called, to send an email to the designated "[email protected]". And it does, it sends an email: I can see that clearly from the logs on my mailtrap account.

But, [email protected] receives nothing. Not in my inbox, and not in my junk email.

Any advice on what could be going on here? Any help would be appreciated

31 Jul
1 month ago

uccdev left a reply on Is It Possible To Have Just The One Log File?

Thank you. I've been advised by my senior to try it, though, so I may try to have another talk about it. Maybe see about getting Forge, while we're at it

uccdev started a new conversation Is It Possible To Have Just The One Log File?

My laravel project in the Atom text editor makes a log file for each day, whenever a file makes a log message for it. e.g "laravel-2019-07-31.log". Tomorrow, when it runs a log message, it'll make "laravel-2019-08-01.log"

I want to instead combine these all into one log file, one which new log messages will go into instead of making a new file for the current date.

Is this possible? How can I go about it? Any tips would be greatly appreciated

23 Jul
1 month ago

uccdev left a reply on Best Practice For Laravel Test Case Helper Functions?

John, thank you very much.

Method #1 works perfectly fine. I'm curious about method #2: how exactly would "CreatesApplication" look like, then, if the helper methods are inside the TestCase class?

uccdev started a new conversation Best Practice For Laravel Test Case Helper Functions?

I'm creating test cases for my laravel project, but I find that I'm repeating a lot of code. I'd like to create helper functions that make it easier to maintain, but I'm not sure what the best practice is for going about that. At the moment my test case looks like this:

     use Tests\TestCase;
     use ...
     ...
     class MyTest extends TestCase {
     
        public function myHelperFunction($arg) {
            return $arg + some actions;
        }
     
        public function testURL() {
            $arg = "my_arg_here";
            $this->assertNotNull($this->myHelperFunction($arg));
        }
            ... //other tests that involve my helper function
     }

One problem among many with the above is that the 'myHelperFunction' is considered its own test, as opposed to something that test cases can use. I need to get around this, but I'm not sure how, without having a trail of redundant code. How best should I implement what I want to implement, would anyone recommend?

12 Jul
2 months ago

uccdev left a reply on File In Console Directory Loses Value Inside Another Function?

@alishahuk Whups. And I'd gotten this right in my other files, too. My mistake. Thank you both!

uccdev started a new conversation File In Console Directory Loses Value Inside Another Function?

So in my laravel project, I've a file in my console folder. "app\Console\Commands\MyCommandFile.php"

To work, it uses a special security token, just like all the other files in this project.

class MyCommand extends Command
{
      protected $accessToken;
      public function __construct()
      {
        $accessToken = config('values.accessToken');
        parent::__construct();
      }
      ...
      public function commandWork() {
            $token = $this->accessToken; //equals null?
             dd($token); //returns null?
             ...
      }
}

This returns null, for some reason. I notice that if I dd($accessToken) in my __construct(), I get the correct value. But when I call for $this->accessToken in commandWork(), I just get null. I don't understand why.

Can anyone offer some clarity or advice on this? Thanks in advance

05 Jul
2 months ago

uccdev left a reply on Can't Get Config Value In Test Case?

I see, thank you for enlightening me. That did the trick!

uccdev started a new conversation Can't Get Config Value In Test Case?

Hi, In one of my test cases, I'm trying to fetch a config value:

    <?php

    namespace Tests\Feature;
    
    use Tests\TestCase;
    use Illuminate\Foundation\Testing\WithFaker;
    use Illuminate\Foundation\Testing\RefreshDatabase;
    use Illuminate\Support\Facades\Facade;
    use App\Http\Controllers\CourseController;
    use App\Config\Values;

    class CurlTest extends TestCase
    {
        protected $token;

        public function __construct() {
          $this->token = config('values.accessToken');
        }
        public function testExample() {
          //some test function
        }
        ...
    }

However, I believe the __construct is giving me an error: Fatal Error: Uncaught ReflectionException: Class config does not exist in C:\directoryPath\Illuminate\Container.php:779

This isn't an error I have in any of my working code that makes this config call, just in this one test case. Can anyone explain to me why this isn't working, and what might instead?

04 Jul
2 months ago

uccdev left a reply on Where And How To Define A Global Controller Variable? "Constant Expression Contains Invalid Operations"

I've removed the return, but I still get the same "Cannot call constructor" error.

uccdev left a reply on Where And How To Define A Global Controller Variable? "Constant Expression Contains Invalid Operations"

I believe that, though I seem to have gotten an error. This code:

  public function __construct(Request $request) {//($finder, Request $request, $pageNum=null) {
      $this->token = config('values.accessToken');
      return parent::__construct();
  }

Gives me this error message: "Cannot call constructor"

uccdev left a reply on Where And How To Define A Global Controller Variable? "Constant Expression Contains Invalid Operations"

My constructor is empty aside from that one definition. Do you think it'd still be necessary?

uccdev left a reply on Where And How To Define A Global Controller Variable? "Constant Expression Contains Invalid Operations"

I'd neglected the $this-> part. That did the trick, thank you.

uccdev left a reply on Where And How To Define A Global Controller Variable? "Constant Expression Contains Invalid Operations"

I'm afraid this did not work. Writing:

     public function findInPage(Request $request, $pageNum=null) 
     {
         echo "<h2>Hi</h2>";
         $myToken = $this->token;
         dd($myToken);
     }

Returns null.

However, a simple:

     dd(config('values.accessToken'))

Works.

uccdev started a new conversation Where And How To Define A Global Controller Variable? "Constant Expression Contains Invalid Operations"

So in my project, I have a special 'token' variable for security. I also have a controller class, and I want to define the token as a variable for it that can be used all over the controller. To give an idea of how it looks:

    class FolderController extends BaseController
    {
         protected $token = config('values.accessToken'); //this returns a legit value, but...
         ...
         public function findInPage($request, $pageNum) { 
                  ...
         }
         public function setHeaders($header) {
                  .... //also uses $token
        }
        public function findBB($pageNum=null) {
                  ...//also uses token
     }

But laravel doesn't like how I'm defining $token. Just doing this causes a runtime error: "Constant expression contains invalid operations".

I'm aware that PHP and controller files like to define their global variables inside constructors, such as:

    public function __construct(Request $request, $pageNum=null) {//($finder, Request $request, $pageNum=null) {
        $token = config('values.accessToken');
        self::findInPage($request, $pageNum); //back on with the program
    }

But this runs into two problems for me:

  • My web routing doesn't point at a constructor function, it points at individual functions based on the feedback given. I'd rather not have to rewrite all my web routing just to go to the constructor.
  • This still doesn't work. $token's definition only exists inside __construct: it ends as soon as I enter "findInPage()"

I reckon I can just use the config() call for the value I want and that'll be enough. But I think it'd be more efficient to define the one variable that I can then call, rather than fetching a resource from a config file every time.

Any advice?

uccdev left a reply on I Don't Understand Request Objects In Laravel

Enlightening, thank you. Though in my instance, I want to use a secret access token as a project-wide variable. Since it is a secret, and something the back-end should know, I don't want it passed in through the URL; it's not something that $_GET or $_POST should see. Maybe request objects aren't really the answer, if I want something like that. Any recommendations?

03 Jul
2 months ago

uccdev left a reply on I Don't Understand Request Objects In Laravel

@RAS1212 - Thank you, ras, though then I'm still wondering why request->all() returns empty

uccdev left a reply on I Don't Understand Request Objects In Laravel

@MUNAZZIL - I see. I've tried this now, but it gave me an empty bracket. "[]". Why would mine be empty? EDIT: Whereas if I do:

    dd($request);

I get:

    Request {#42 ▼
      #json: null
      #convertedFiles: null
      #userResolver: Closure($guard = null) {#171 ▶}
      #routeResolver: Closure() {#173 ▶}
      +attributes: ParameterBag {#44 ▶}
      +request: ParameterBag {#50 ▶}
      +query: ParameterBag {#50 ▶}
      +server: ServerBag {#46 ▶}
      +files: FileBag {#47 ▶}
      +cookies: ParameterBag {#45 ▶}
      +headers: HeaderBag {#48 ▶}
      #content: null
      #languages: null
      #charsets: null
      #encodings: null
      #acceptableContentTypes: null
      #pathInfo: "/testurl/1"
      #requestUri: "/testurl/1"
      #baseUrl: ""
      #basePath: null
      #method: "GET"
      #format: null
      #session: Store {#211 ▶}
      #locale: null
      #defaultLocale: "en"
      -isHostValid: true
      -isForwardedValid: true
      basePath: ""
      format: "html"
    }

uccdev left a reply on I Don't Understand Request Objects In Laravel

@NAKOV - I think I see. Though in this instance, how could I use a Request object for test cases? Those don't use URL routing, if I recall correctly, they're called from the command line

uccdev left a reply on I Don't Understand Request Objects In Laravel

@NAKOV - Can you give me a practical example of it in action please? For instance, if I have the function:

    public function searchData(Request $request) {
            ....
    }

How would I create a $request for "searchData($request)" to call?

uccdev left a reply on I Don't Understand Request Objects In Laravel

@MUNAZZIL - Where does the "Request $request" come from, though? I can create a function argument like that, fine, but then I have to call the function and give it an object. How does that part work out?

uccdev started a new conversation I Don't Understand Request Objects In Laravel

Hi,

Often I'll read through resources like the laravel documentation on Sessions (https://laravel.com/docs/5.3/session#retrieving-data). Each time I'll see something like "Request $request".

I understand that I use a Request object from "Illuminate\Http\Request;" But there are some things I just don't get about it.

  • How do I create a Request object to be passed into any given function that needs it? For the sake of using anything I may need? (e.g $request->session()->get('key', 'default')).
  • Why/how is this object necessary for interfacing with other files in my laravel project? Apparently sessions are the key to using project-wide variables, while request objects are how we access those? I feel I'm barely scratching the surface of it with this understanding.

Any help and/or clarity would be greatly appreciated

01 Jul
2 months ago

uccdev left a reply on Test Case Can't Open File In Public Directory?

@JOHNBRAUN - That's a handy resource to have, I'll bookmark it

uccdev left a reply on Test Case Can't Open File In Public Directory?

@MVD - That did the trick! Thanks for clarifying. Everything's working now!

uccdev started a new conversation Test Case Can't Open File In Public Directory?

Hi, In my current laravel project, I have a controller function that can find a file "courses.csv" just fine in my public directory ("myProject\public\courses.csv").

Now I want to test it can always find this in my test case code:

    public function testOpenCourse() {
          $course = new CourseController();
          $course_list = $course->openCourse();
          $this->assertNotNull(fgets($course_list));
    }

Where 'openCourse()' simply reads this:

    public function openCourse() {
        return fopen("courses.csv", "r");
    }

Rather than assert anything, when I run my phpunit for test cases, I instead get an error: "ErrorException: fopen(file.csv): failed to open stream: No such file or directory"

Why is this happening?

25 Jun
2 months ago

uccdev started a new conversation Best Practice For Test Cases For CURL Testing?

Hi,

I'm using laravel frameworks to commit cURL requests and process its data. I'm able to do these things fine, but I want to build test cases for them too.

Here is an example of a cURL request function I might use:

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

     $curl = curl_init();
     $url = "https://my.instructure.com/api/v1/accounts/1/courses?sort=created_at&order=desc&per_page=30";  

     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 => 0,
   CURLOPT_RETURNTRANSFER, TRUE
]);
     if (curl_errno($curl)) {
       echo 'Error:' . curl_error($curl) . "<br>";
     } else { echo " all good<br>"; }
     $resp = curl_exec($curl);
     $data = json_decode($resp, true);
     curl_close($curl);
     return $data[0];
   }

My question, to be clear, is if given a request and an action like this, what kinds of unit test cases could I make for them? I feel like I'd have to restructure the code to test each individual part, but I'm not sure how

Any help would be greatly appreciated

22 May
4 months ago

uccdev started a new conversation "Call To Undefined Method App\Console\Kernel::job()"

I'm running a schedule on my laravel class which goes like this:

      protected function schedule(Schedule $schedule)
      {
                $schedule->call(function () {
                          $schedule->job(new ServerJob("hi"));
                })->everyFiveMinutes();
      }

When I run this, I get an error message in the logs:

     [2019-05-22 15:15:02] local.ERROR: Call to undefined method App\Console\Kernel::job() {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Call to undefined method App\Console\Kernel::job() at /home/vagrant/myProject/myApp/app/Console/Kernel.php:37)

[stacktrace]

How do I fix this? I know that if I use "$schedule->job(...)" outside of schedule, it all works fine, but I'm trying to use this method to solve a scheduling issue (as listed here: https://www.laracasts.com/discuss/channels/laravel/task-scheduling-runs-every-minute-despite-my-directions)

Any advice?

uccdev left a reply on Task Scheduling Runs Every Minute Despite My Directions

@CLICK - Click, thanks for your reply. But I'm still unsure. First, I'm not simply doing this:

       new serverJob("hi");

I'm doing:

       new serverJob("hi")->everyTenMinutes();

Yet it's still being called every minute.

Second, I've tried the callable exactly as you wrote it:

       $schedule->call(function () {
            $this->job(new ServerJob("hi"));
       })->daily();

yet...it doesn't seem to work at all. I get no initial call from it at all. I only get the log messages from outside the call, none of those inside the Job. It's like there's some error in the code. Not sure where to go from there?

EDIT: To be clear, in the logs, I get this error message:

                    local.ERROR: Call to undefined method App\Console\Kernel::job()
21 May
4 months ago

uccdev left a reply on Task Scheduling Runs Every Minute Despite My Directions

@SNAPEY - @snapey Thank you. I have been logging in the job itself, and I can confirm that it is running every minute there. I also send an email to a test account with this schedule, and that has been going every minute too.

17 May
4 months ago

uccdev left a reply on Task Scheduling Runs Every Minute Despite My Directions

Having investigated, I believe it's not due to any of the code I wrote here, but how I called my scheduler from the server itself:

              * * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

I should change the number from "1" to another value, according to how many minutes I want to run it for.

uccdev started a new conversation Task Scheduling Runs Every Minute Despite My Directions

Hi,

I'm scheduling my app/console/Kernel.php to run the following code every fifteen minutes:

       protected function schedule(Schedule $schedule)
       {
               Log::info('now im attmept schedule');
               $schedule->job(new ServerJob("hi"))->everyFifteenMinutes();
               Log::info('i doon');
       }

The problem is, this isn't running every fifteen minutes, it is running every ONE minute.

The schedule calls the following job:

     public function __construct($serveJob)
     {
           Log::info("Job constructor");
           $this->serveJob = $serveJob;
           self::findBBDirect();
           self::testEmail();
           Log::info("job's dun");
     }

That job's functions look, right now, like:

    public function testEmail() {
          Log::info("Test email");
          Mail::send("testCurl", [],
          function($message) { //use ($filePath)
            $message->to('[email protected]', 'Artisans Web')
            ->subject('Marco Polo');
            $message->from('[email protected]', 'Sample name');
          });
        }

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

          $curl = curl_init();
          $validReturn = true;
          $url = "https://my.instructure.com/api/v1/accounts/1/courses?per_page=100";

          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,
            CURLOPT_RETURNTRANSFER, TRUE
          ]);
          if (curl_errno($curl)) {
            Log::info('Error:' . curl_error($curl));
          } else {
            Log::info('Yep, curl is fine');
          }

          $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);
          $bbData = array_fill(0, 4, null);
          $numBBs = 0;
          foreach ($data as $d) {
            if((array_key_exists("id", $d)) && (self::hasBBDirect($d["id"]))) {
              Log::info("found BB");
              $bbData[$numBBs] = $d["id"];
              $numBBs++;
            }
          }
          curl_close($curl);
    }

It may also be of interest that this was not running irregularly until recently. I don't know what change I made to cause this, but I can't seem to go back to it.

Any ideas why this would happen?

To clarify, I've seen this thread as well: https://laracasts.com/discuss/channels/general-discussion/task-scheduling-runs-every-minute-instead-of-the-time-that-i-set . But since I am not giving any specific cron directions, or usage, I am not sure the advice within is applicable here. I am extra unsure, in fact, since just two days ago, all was working as I had expected it to. That it isn't now, I don't know what to do.

Any help would be greatly appreciated

15 May
4 months ago

uccdev left a reply on Laravel Not Creating Log File?

The issue was simply that my Homestead virtual machine hadn't loaded properly. A simple restart did the trick.

uccdev started a new conversation Laravel Not Creating Log File?

I've got a laravel schedule running on my server, but despite successful execution, I am not getting a log file for today. I have log files for yesterday but not today.

Why does something like this happen? What can I do about it?

EDIT: To clarify, my config/app.php is currently set up as:

      'aliases' => [
    ...
            'Log' => Illuminate\Support\Facades\Log::class,
    ...
  ], ...

So it makes different log files, one per day. However, it's not made today's log file. I don't understand why.

EDIT: Disregard. The issue was simply that my Homestead virtual machine hadn't loaded properly. A simple restart did the trick.

uccdev started a new conversation Schedule A Job From A Controller?

So I've got a server I want to schedule certain functions on. I've got a controller and functions in it. And I've got a Job that dispatches commands.

I know that my scheduler cannot call controller functions, it must call a job.

I know that I can put functions inside my job file, though such seems redundant, especially following the advice from this link, that says to have controllers call jobs: https://laracasts.com/discuss/channels/laravel/call-controller-method-inside-a-job-handle-method

So what is the conventionally best way? Is what I'm asking for in the title possible or recommended?

09 May
4 months ago

uccdev left a reply on How To Call A Controller Function From Schedule And Pass Parameters

@MARTINBEAN - Hey Martin, just saw this myself while having the same problem that wassim had. I'm learning about jobs and queues now from the documentation, but in the case of your example, can you describe for me what "new YourJobName" would look like?

03 May
4 months ago

uccdev started a new conversation Do I Need Cron To Use Schedulers On Homestead?

Hi,

I'm running laravel through a virtual machine run by homestead at the moment. I've set schedule = true in my Homestead.yaml and I've edited my schedule() function to run a simple email every ten minutes:

          protected function schedule(Schedule $schedule)
          {
                  $schedule->call('[email protected]')
                  ->everyTenMinutes();
          }

It doesn't seem to be enough, though, so I'm wondering if there's anything else I need to do? I haven't installed cron or called anything on the command line, I just have Homestead up and running.

P.S does it matter if I'm using windows if I want to install cron?

02 May
4 months ago

uccdev started a new conversation Do I Need Cron To Use Schedulers On Homestead?

Hi,

I'm running laravel through a virtual machine run by homestead at the moment. I've set schedule = true in my Homestead.yaml and I've edited my schedule() function to run a simple email every ten minutes:

                 protected function schedule(Schedule $schedule)
                 {
                         $schedule->call('[email protected]')
                         ->everyTenMinutes();
                 }

It doesn't seem to be enough, though, so I'm wondering if there's anything else I need to do? I haven't installed cron or called anything on the command line, I just have Homestead up and running.

P.S does it matter if I'm using windows if I want to install cron?

25 Apr
4 months ago

uccdev started a new conversation Write A Command Line Script In Laravel To Check Courses?

Hi, I'm trying to search every account in my endpoint https://my.test.instructure.com/api/v1/accounts/1/courses

I've written a laravel browser application that can let me check them individually, but now I need a command line script that, when automated, will comb through ALL the entries here, see if they have a certain folder, and then delete that folder if so.

I've checked laracasts and the broader web, but so much of their information seems to be about main laravel web applications (which isn't what I'm looking for). Does anyone have any advice how best I might go about solving this? Any help would be kindly appreciated.

24 Apr
4 months ago

uccdev left a reply on Laravel Controller Is Not Returning To View?

@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!

23 Apr
4 months ago

uccdev left a reply on Laravel Controller Is Not Returning To View?

@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', '[email protected]')
18 Apr
5 months ago

uccdev started a new conversation 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?

08 Apr
5 months ago

uccdev started a new conversation Can I Check Each Of My Courses For A Certain Folder More Efficiently Than This?

Hi, I am checking all the courses in my Canvas database to see which ones have a certain folder. Let's call this folder "BB_Direct."

At the moment, using cUrl requests like below, I check the accounts/number/courses endpoint to retrieve all the courses:

  $loop = 1; //increments with each loop
  $validReturn = true;

while($validReturn) {
  curl_setopt_array($curl, [
    CURLOPT_RETURNTRANSFER => true,
    CURLINFO_HEADER_OUT => true,
    CURLOPT_URL => "https://my.test.instructure.com/api/v1/accounts/$loop/courses?by_subaccounts[100]&per_page=100",//?by_subaccounts[95]&per_page=100/",//'https://ucc.test.instructure.com/api/v1/courses',
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_SSL_VERIFYPEER => true,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_CUSTOMREQUEST, 'GET',
    CURLOPT_RETURNTRANSFER, true
  ]);
 $resp = curl_exec($curl);
  $data = json_decode($resp, true);
  if (array_key_exists("errors", $data)) { //assuming that there are NO valid pages after the latest retrieved one that returns "error"
    $validReturn = false;
    echo "Invalid page found. Ending after loop $loop</br>";
  }
  else {
    echo "Loop $loop <br>";
    //dd($data);
  //dd($data);
    foreach ($data as $d) {
      if((array_key_exists("id", $d)) && (self::hasBBDirect($d["id"]))) { //important line
        echo "BB_Direct folder FOUND in course " . $d["id"] . "</br>";
      } else {
        echo "No BB_Direct folder found in course " . $d["id"] . "<br>";
      }
    }
    $loop++;
  }

See the "self::hasBBDirect($d["id"])" line? That directs to a helper function to check if any courses under the returned course ID have the folder I'm looking for:

   public function hasBBDirect($courseID) {
       $token = "insert_token_here";
       $headers = ['Authorization: Bearer ' . $token];
       $curl = curl_init();
       $url = "https://my.test.instructure.com/api/v1/courses/$courseID/folders/by_path/BB_Direct"; //"BB_Direct" = the folder I'm looking for

       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_RETURNTRANSFER, true
]);

       $resp = curl_exec($curl);
       $data = json_decode($resp, true);
       if(array_key_exists("errors", $data)) {
         return False;
       } else { //presumably, the given course has a BB_Direct folder after all then
         return True;
       }
 }

Now, the code I have listed works, it does what I want it to do. But the dataset I am working on has 7000 entries in it, so this takes a lot of time to compute. My question is, how can I OPTIMISE this? Can I find a certain folder in my list of courses any more efficiently?

Any thoughts anyone could lend me would be greatly appreciated