fogley

fogley

Member Since 1 Year Ago

Experience Points 910
Experience Level 1

4,090 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 0
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.

19 Aug
2 days ago
14 Aug
1 week ago

fogley started a new conversation Cancel A Running Job/force A Fail

My users need to be able to cancel a running job. The fail() method for the job makes sure that it crashes gracefully so I basically only need to make the job fail on purpose.

Is this possible using PHP/Laravel?

Any other possible solution to stop a running job without rebooting the queue process and removing the job from the queue?

08 Apr
4 months ago

fogley left a reply on Multiple Queue Workers Borks The System

Setting retry_after solved it. These jobs can last days, so I upped it to a week. Thanks.

03 Apr
4 months ago

fogley started a new conversation Multiple Queue Workers Borks The System

As soon as I run more than 1 worker on my server, they all jump on the first job they see and make it fail because it exceeds the retries (which is 1). The first job to grab it will keep working as though nothing happened, making the database inconsistent...

I thought Laravel was capable of handling multiple workers by default. Why are they taking up already running jobs? Am I missing something?

My queue driver is database. Database platform is Postgres.

19 Dec
8 months ago

fogley left a reply on Custom Save Method For Model Returning False On Unique Constraint Violation

@AHMEDDABAK - uniqid() returns an (at least) 13 character long string which is not viable for me. I need to be able to save guaranteed unique strings of 5 characters in length.

fogley left a reply on Custom Save Method For Model Returning False On Unique Constraint Violation

@AHMEDDABAK - The thing is, the data created is a randomized string used as an identifier, there's nothing to redirect to. This is only used in internal loops to create an entry with valid data:

while(!$model->saveOrFalse()){
    $model->identifier = str_random(5);
}

This saves me a loop to check the current values in the DB before saving the model.

fogley started a new conversation Custom Save Method For Model Returning False On Unique Constraint Violation

So, I'm a little tired of constantly combating whether or not I'm currently about to violate a unique constraint in my database. As an experiment I've made the following model function that silently processes the 23000 constraint violation error code and returns false if one such should occur.

    public function saveOrFalse(){
        try{
            return $this->save();
        }catch(QueryException $e){
            if($e->getCode() == 23000){
                return false;
            }
            return $e;
        }
    }

It works precisely as I would expect and could end up lighten my workload a lot.

How would I go about adding this function to the Model class itself so I can avoid adding it to all my classes manually? Is this a bad idea? How bad practice is this? Is the overhead massive compared to checking prior to saving?

Assuming it's out of the question for any sane developer, do you have any alternatives?

14 Nov
9 months ago

fogley left a reply on Dd Converts Large Associative Array To Numeric?

Around 60.000 elements.

I've been doing some tests and the values in the numeric array corresponds to the ones in the associative array...

I have a very hard time seeing how this is in any way handy... Unless I'm missing something.

13 Nov
9 months ago

fogley started a new conversation Dd Converts Large Associative Array To Numeric?

I've been dumping a lot of test data and it seems that dd converts associative arrays to numeric when the amount of data exceeds a certain threshold. Is that correct?

06 Nov
9 months ago

fogley started a new conversation Cannot Drop Column And Add New Columns In Same Migration

I've created a migration that is supposed to drop columns as well as create new ones. When I drop the column, the migration does not add the the columns.

When I remove the dropColumn call, the columns are added just fine. I use SQLite.

Here's the simplified version:

    Schema::table('table', function($table) {
        $table->integer('new_column_name')->nullable();
        $table->dropColumn('old_column_name');
    });
05 Nov
9 months ago

fogley started a new conversation Parse Date According To Specific Format

I trying to parse user submitted dates that vary wildly in format. So, to accommodate this I enable users to set the used format so that the system can save dates in a consistent format.

But, I cannot figure out if it's at all possible to tell Carbon to parse an arbitrary date string in a given format. And, if not: Is there any other realistic solution to this problem?

30 Oct
9 months ago

fogley left a reply on Cannot Call Custom Job Method Withing Job Itself

This is the gist of it:

$db_data = Model::all();
if($db_data->where('column', 'value')->exists()){
    // do stuff
}

Using first() instead of exists() solved the problem.

fogley left a reply on Cannot Call Custom Job Method Withing Job Itself

Turns out I was using the exists() method on an already declared DB collection. So, I ended up using the first() method instead and treating the returned data as a boolean.

Is this an oversight? Why can't I use the exists() method on existing collections?

fogley started a new conversation Cannot Call Custom Job Method Withing Job Itself

I have created a Job containing a few helper methods, contained within the job class itself. When I try to call the methods ($this->method($params);), I get an error that the method does not exist.

Any ideas?

16 Oct
10 months ago

fogley left a reply on Only Process Jobs One At A Time

Ah, okay. Thanks!

fogley started a new conversation Only Process Jobs One At A Time

I want to process jobs chronologically, as in: Only one job running at any given time.

Is it correct if I assume that this is done by adding the --once option to the worker?

php artisan queue:work --once

Or will this kill the process once its done?

15 Oct
10 months ago

fogley started a new conversation Special Characters Will Not Print

When I fetch text data from my SQLite DB with special characters (ä), the string containing the character has the character b prefixed to the string, dd'ing the data looks like this:

"column_name" => b"text containing ä

This doesn't print anything when printed in views like so:

{{ $object->column_name }}

Any fixes?

fogley started a new conversation Fetch Model Where Relationship Model Has Specific Values

I'm trying to fetch records with specific values as well as specific values related to their belongsTo model.

So, I would write it like so:

$records = Records::where('belongsto.column', 'value')->orWhere('column', 'another_value')->get();

Is there a way to do this or do I need to chop it up?

11 Oct
10 months ago

fogley left a reply on Jobs Cant Use The Info() Helper Function

Ah. It seems I need to restart the queue worker when I've made changes to the Job class. Makes sense.

fogley left a reply on Jobs Cant Use The Info() Helper Function

That also does nothing...

fogley started a new conversation Jobs Cant Use The Info() Helper Function

I'm debugging a Job class, but I can't get it to write to the log using the info() helper function. My controllers can do so with no problem...

Solutions?

07 Sep
11 months ago

fogley left a reply on Redirect With Data

I cannot fetch the data transferred like this. If I reference it like this {{ $variable }} it returns an error because it's undefined.

fogley started a new conversation Redirect With Data

Is there a way to pass data to a redirection in the same vein as when returning views?

Like this

return redirect->('/home')->with('variable', 'variable data')

I'm aware that I can do the following, but that transfers the data via GET which I'm not interested in:

return redirect()->route('home', ['variable' => 'variabledata']);

05 Sep
11 months ago
04 Sep
11 months ago

fogley left a reply on Getting Distinct Data Based On Specific Columns

I updated the original post to better reflect what I need help with.

fogley left a reply on Getting Distinct Data Based On Specific Columns

Isn't that exactly what the latest() method is for? - I've tried this with no luck.

fogley started a new conversation Getting Distinct Data Based On Specific Columns

Right now, when I run distinct() on my query it will fetch the whole table. I suspect this is because I have timestamps enabled. So even though all the important columns are the same, the query will treat the data as different because it contains different timestamps. I am only interested in the unique data set, disregarding the timestamps.

Is there a way to tell the query builder to only observe specific columns when deciding whether or not data is distinct?

Basically, I need ALL the columns from the table. But ONLY the newest entry and ONLY if all columns EXCEPT created_at/updated_at are identical to any other entry.

Intuitively, I would do it like this:

Users::latest()->distinct('column1', 'column2', 'column3')->get();

Where column1, column2, column3 corresponds to the columns I want to compare to determine if data is distinct.

03 Sep
11 months ago

fogley started a new conversation Can I Really Not Pass A Multidimensional Array To WhereIn? - Creating Dynamic WhereIn Clauses

I've been fighting with how to dynamically create a database query with potentially many whereIn clauses. So, I tried feeding the method a multidimensional array like so:

//append data to the $whereIn array as needed
$whereIn = ['id' => [1,2,3], 'email' => ['[email protected]', '[email protected]']];

Users::whereIn($whereIn)->get();

How the above should work is obvious to me (I hope it is for you as well).

So, seeing as this does not work, how would I go about making a dynamically created whereIn clause?

The only solution I can think of is an ungodly if/else with all possible outcomes, but that hurts my brain.

15 Jun
1 year ago

fogley left a reply on Access Forbidden On Non-HTTPS Connections In Apache

Like I wrote, the posted config is deliberately not the default Certbot-generated one as that was the one that created the problem to begin with.

I really have no clue what's causing this, it's a little baffling.

11 Jun
1 year ago

fogley started a new conversation Access Forbidden On Non-HTTPS Connections In Apache

I have a 5.5 installation running on a virtual host in Apache 2, encrypted by Certbot/LetsEncypt.

The HTTPS access works just fine, but accessing it through HTTP poses problems:

Even though I activated automatic redirect when installing the certificate, the server does not redirect to a secure connection. - Instead, Apache simply returns a forbidden error.

I have tried different tweaks in both the virtualhost config as well as in Laravel's own .htaccess with no luck. Do you guys have any idea how to resolve this/enabling a working HTTP to HTTPS redirect?

Below is my virtualhost config (I tried tweaking the redirect clause, so it's not the default Certbot version):

        DocumentRoot /var/www/[domain.tld]/public
    ServerName [domain.tld]

        <Directory /var/www/[domain.tld]/public>
            Options -Indexes
            AllowOverride All
            Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

        RewriteEngine on
        RewriteCond %{HTTPS} !=on
        RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]