Kryptonit3

Kryptonit3

Member Since 5 Years Ago

Louisville, KY, USA

Time Warner Contract Technician at G&C Communications

Experience Points 48,425
Experience Level 10

1,575 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 93
Lessons
Completed
Best Reply Awards 34
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

09 Jun
9 months ago

Kryptonit3 left a reply on L5.2 Unix Timestamp On Created_at And Updated_at

I know this is old, but so you don't mess with Laravel default timestamps, do the following on your model.

    public function toSearchableArray()
    {
        $array = $this->toArray();

        $array['updated_at_unix'] = $this->updated_at->timestamp;

        return $array;
    }

No need for a new database column. This will create a Algolia "column" on your index that is now sortable.

03 Jun
9 months ago

Kryptonit3 left a reply on $error->has() For ANY Errors In Input Array

I know this is old but I have found a solution that works for me for my dynamically generated inputs. (http://formvalidation.io/examples/adding-dynamic-field/)

@if($errors->has('*'))
                        <?php $count = 1; ?>
                        @foreach($errors->all() as $error)
                            @if($errors->has('identifiers.' . $count . '.*'))
                                <div data-identifier-index="{{ $count }}">
                                    <div class="row mb-2 newIdentifier">
                                        <div class="col-5">
                                            <input type="text" class="form-control {{ $errors->has('identifiers.'.$count.'.name') ? 'is-invalid' : '' }}" name="identifiers[{{ $count }}][name]" value="{{ old('identifiers.'.$count.'.name') }}" placeholder="Name: CMAC, S/N">
                                            @if($errors->has('identifiers.'.$count.'.name'))
                                                <div class="invalid-feedback">
                                                    <p class="m-0">
                                                        {{ $errors->first('identifiers.'.$count.'.name') }}
                                                    </p>
                                                </div>
                                            @endif
                                        </div>
                                        <div class="col-5">
                                            <input type="text" class="form-control {{ $errors->has('identifiers.'.$count.'.value') ? 'is-invalid' : '' }}" name="identifiers[{{ $count }}][value]" value="{{ old('identifiers.'.$count.'.value') }}" placeholder="Value">
                                            @if($errors->has('identifiers.'.$count.'.value'))
                                                <div class="invalid-feedback">
                                                    <p class="m-0">
                                                        {{ $errors->first('identifiers.'.$count.'.value') }}
                                                    </p>
                                                </div>
                                            @endif
                                        </div>
                                        <div class="col">
                                            <button class="btn btn-sm btn-danger removeButton mt-1">Remove</button>
                                        </div>
                                    </div>
                                </div>
                                <?php $count++ ?>
                            @endif
                        @endforeach
                    @endif 
30 Apr
10 months ago

Kryptonit3 left a reply on Database Stored JSON Not Casting To PHP Array

Figured it out. Data going into the model is expected to be an array, not already json. In my seed file I changed the line $user->availability = $json; to $user->availabilty = json_decode($json, true);so the Model would receive what it was looking for... a php array. Nowphp artisan tinker` shows good data.

>>> $user = TwilioUser::first();
[!] Aliasing 'TwilioUser' to 'App\TwilioUser' for this Tinker session.
=> App\TwilioUser {#2394
     id: 1,
     created_by: 1,
     updated_by: null,
     name: "User Name",
     number: "+15025551234",
     extension: "701",
     availability: "{"friday": {"end": "17:00:00", "start": "09:00:00", "enabled": true}, "monday": {"end": "17:00:00", "start": "09:00:00", "enabled": true}, "sunday": {"end": "17:00:00", "start": "09:00:00", "enabled": true}, "tuesday": {"end": "17:00:00", "start": "09:00:00", "enabled": true}, "saturday": {"end": "17:00:00", "start": "09:00:00", "enabled": true}, "thursday": {"end": "17:00:00", "start": "09:00:00", "enabled": true}, "wednesday": {"end": "17:00:00", "start": "09:00:00", "enabled": true}}",
     calls_enabled: 1,
     dial_by_extension_enabled: 1,
     created_at: "2018-04-30 18:32:13",
     updated_at: "2018-04-30 18:32:13",
   }
>>> $user->availability
=> [
     "friday" => [
       "end" => "17:00:00",
       "start" => "09:00:00",
       "enabled" => true,
     ],
     "monday" => [
       "end" => "17:00:00",
       "start" => "09:00:00",
       "enabled" => true,
     ],
     "sunday" => [
       "end" => "17:00:00",
       "start" => "09:00:00",
       "enabled" => true,
     ],
     "tuesday" => [
       "end" => "17:00:00",
       "start" => "09:00:00",
       "enabled" => true,
     ],
     "saturday" => [
       "end" => "17:00:00",
       "start" => "09:00:00",
       "enabled" => true,
     ],
     "thursday" => [
       "end" => "17:00:00",
       "start" => "09:00:00",
       "enabled" => true,
     ],
     "wednesday" => [
       "end" => "17:00:00",
       "start" => "09:00:00",
       "enabled" => true,
     ],
   ]

Kryptonit3 left a reply on Database Stored JSON Not Casting To PHP Array

Tried all three types, json, object, array and dd($user->availability) never changes.

Am I accessing the data improperly to invoke the casting?

Kryptonit3 left a reply on Database Stored JSON Not Casting To PHP Array

@Cronix yeah, I knew I could get and set. My example shows me retrieving a model and attempting to access the availability property. Right? O.o

Kryptonit3 started a new conversation Database Stored JSON Not Casting To PHP Array

Laravel version: 5.6.18

Database Scema

        Schema::create('twilio_users', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('created_by')->unsigned();
            $table->foreign('created_by')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
            $table->integer('updated_by')->unsigned()->nullable();
            $table->foreign('updated_by')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
            $table->string('name');
            $table->string('number');
            $table->string('extension')->nullable();
            $table->json('availability');
            $table->boolean('calls_enabled')->default(true);
            $table->boolean('dial_by_extension_enabled')->default(true)->nullable();
            $table->timestamps();
        });

TwilioUser Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class TwilioUser extends Model
{
    protected $casts = [
        'availability' => 'array',
    ];
}

TwilioUserTableSeeder.php

<?php

use Illuminate\Database\Seeder;

use App\User;
use App\TwilioUser;

class TwilioUserTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $created = User::first();
        $json = File::get('database/seeds/data/twilio_user_table_seed.json');
        $user = new TwilioUser();
        $user->created_by = $created->id;
        $user->name = 'User Name';
        $user->number = '+15025551234';
        $user->extension = '701';
        $user->calls_enabled = true;
        $user->dial_by_extension_enabled = true;
        $user->availability = $json;
        $user->save();
    }
}

\database\seeds\data\twilio_user_table_seed.json

{"sunday":{"enabled":true,"start":"09:00:00","end":"17:00:00"},"monday":{"enabled":true,"start":"09:00:00","end":"17:00:00"},"tuesday":{"enabled":true,"start":"09:00:00","end":"17:00:00"},"wednesday":{"enabled":true,"start":"09:00:00","end":"17:00:00"},"thursday":{"enabled":true,"start":"09:00:00","end":"17:00:00"},"friday":{"enabled":true,"start":"09:00:00","end":"17:00:00"},"saturday":{"enabled":true,"start":"09:00:00","end":"17:00:00"}}

php artisan tinker output depicting issue

>>> $user = TwilioUser::first();
=> App\TwilioUser {#2384
     id: 1,
     created_by: 1,
     updated_by: null,
     name: "User Name",
     number: "+15025551234",
     extension: "701",
     availability: ""{\"sunday\":{\"enabled\":true,\"start\":\"09:00:00\",\"end\":\"17:00:00\"},\"monday\":{\"enabled\":true,\"start\":\"09:00:00\",\"end\":\"17:00:00\"},\"tuesday\":{\"enabled\":true,\"start\":\"09:00:00\",\"end\":\"17:00:00\"},\"wednesday\":{\"enabled\":true,\"start\":\"09:00:00\",\"end\":\"17:00:00\"},\"thursday\":{\"enabled\":true,\"start\":\"09:00:00\",\"end\":\"17:00:00\"},\"friday\":{\"enabled\":true,\"start\":\"09:00:00\",\"end\":\"17:00:00\"},\"saturday\":{\"enabled\":true,\"start\":\"09:00:00\",\"end\":\"17:00:00\"}}"",
     calls_enabled: 1,
     dial_by_extension_enabled: 1,
     created_at: "2018-04-30 16:40:39",
     updated_at: "2018-04-30 16:40:39",
   }
>>> $availability = $user->availability;
=> "{"sunday":{"enabled":true,"start":"09:00:00","end":"17:00:00"},"monday":{"enabled":true,"start":"09:00:00","end":"17:00:00"},"tuesday":{"enabled":true,"start":"09:00:00","end":"17:00:00"},"wednesday":{"enabled":true,"start":"09:00:00","end":"17:00:00"},"thursday":{"enabled":true,"start":"09:00:00","end":"17:00:00"},"friday":{"enabled":true,"start":"09:00:00","end":"17:00:00"},"saturday":{"enabled":true,"start":"09:00:00","end":"17:00:00"}}"
>>> $availability->sunday
PHP Notice:  Trying to get property 'sunday' of non-object in Psy Shell code on line 1
>>> $availability['sunday']
PHP Warning:  Illegal string offset 'sunday' in Psy Shell code on line 1
>>>

Am I missing something? I may not be understanding the whole "Casting" thing. Was really hoping to be able to use the auto translate between the database and the code instead of having to perform encode and decodes.

Thanks in advance.

06 Jul
2 years ago

Kryptonit3 left a reply on App Key Any Vulnerability?

That is the package authors recommendation. Taylor has implemented the phpdotenv in a way that it is safe (ignored by git) and out of the public eye (directory).

While you can very much code your database, api etc credentials in their respective config files, utilizing .env at least when it pertains to Laravel is ideal especially if you are building an app that will be used in multiple environments, and safer if you utilize version control so your production/dev credentials aren't sprawled across commit history.

Kryptonit3 left a reply on URL Query Strings Not Working (pagination)

nvm, was missing dollar sign before "query_string"

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

Kryptonit3 left a reply on App Key Any Vulnerability?

@Raimondas np

You should almost never hard code a config file. You can create your on variables in your .env file and reference them inside your code with the env helper function.

Like in .env you could do MY_API_KEY=93489384 and inside your config file itself you would put env('MY_API_KEY') that way you could just edit .env for dev API key and production API key without having to affect the versioning and having different branches for dev and production.

https://laravel.com/docs/5.2/configuration#environment-configuration

Kryptonit3 left a reply on App Key Any Vulnerability?

on the production server yes. and make sure debug is false. on your local dev server it should be local env and debug to true to work out bugs/errors.

Kryptonit3 left a reply on App Key Any Vulnerability?

@jlrdw a ".env" file is what allows the code to be portable if you plan on using same code for multiple sites. It is a cleaner approach than hard coding. Plus, if you use github or other git version control sites and have config files blank for dev while using .env file but filled in on production and not using an .env file you will either have to have a separate branch for those specific changes or you will get an error if you try to "git pull" any updates. There is a reason in the .env file you can change the environment from "local" to "production" and also have the ability to enable and disable debug mode. All while circumventing any version control issues due to .env being included in .gitignore

Kryptonit3 started a new conversation URL Query Strings Not Working (pagination)

I built a warehouse management site for my previous company and they have recently expanded into another market. I had the original site on the base domain https://gandc.co now that they have opened a shop in another market I moved the base domain code to a subdomain https://louisville.gandc.co - The site 99% works as it should. I did migrate all the code to a new digital ocean droplet. My previously working install on the base domain was running Ubuntu 14.04 with nginx, mysql, and php 5.x . On the new server I decided to go with the new Ubuntu 16.04. Its default PHP is version 7. I think this may be my issue but not sure as to why due to my nginx configs staying the same.

If I go to a page with paginated data and click "2", the url will append with myurl.com?page=2 but the data doesn't change. It is like PHP or nginx isnt passing the URL query string.

Here is my nginx config in question. Worked fine on old server with older PHP

kryptonit3@ubuntu-2gb-nyc3-01:~$ sudo cat /etc/nginx/sites-enabled/louisville.gandc.co
[sudo] password for kryptonit3:
server {
    listen 80;
    listen [::]:80;
    server_name louisville.gandc.co;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    charset utf-8;

    ssl_certificate /etc/letsencrypt/live/louisville.gandc.co/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/louisville.gandc.co/privkey.pem;

    include snippets/ssl-params.conf;

    root /var/www/gandc/subdomains/louisville/html/public;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name louisville.gandc.co;

    location / {
        try_files $uri $uri/ /index.php?query_string;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location ~ /.well-known {
        allow all;
    }
}

Any ideas? I also switched from using a regular SSL to using https://letsencrypt.org so I wouldn't have to pay high price for wildcard SSL.

05 Mar
3 years ago

Kryptonit3 left a reply on [Stripe][Cashier] Get Model Records Where User Is Subscribed()

Maybe this is a working solution. I tried following the logic @TaylorOtwell uses in the Cashier package to check if the subscription is active. I have added this as the query scope on the Listing model.

public function scopeSubscribed($query)
{
    return $query->whereHas('user', function ($r) {
                $r->whereHas('subscriptions', function ($s) {
                    $s->whereNested(function ($t) {
                        $t->where('name', 'main') // name of subscription
                            ->whereNull('ends_at')
                            ->orWhere('ends_at', '>', Carbon::now())
                            ->orWhereNotNull('trial_ends_at')
                            ->where('trial_ends_at', '>', Carbon::today());
                    });
                });
            });
}

It appears to work. Sucks It has to be done like this.

Kryptonit3 started a new conversation [Stripe][Cashier] Get Model Records Where User Is Subscribed()

I am unsure on how to do the following. I would like to get records from a model where the related User model is subscribed to a stripe plan. Here is an example of what I am talking about.

User Model

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Cashier\Billable;

class User extends Authenticatable
{
    use Billable;

    protected $fillable = [
        'first_name', 'last_name', 'username',
        'email', 'password'
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];

    public function listings()
    {
        return $this->hasMany(Listing::class);
    }
}

Listing Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Listing extends Model
{
    use Billable, SoftDeletes;

    protected $fillable = [
        'title'
    ];

    public function user()
    {
        return $this->belongsTo(User::class);
    }
}

I would like to be able to get all Listing where the user is subscribed. Now I can easily see if a specific user is subscribed with $user->subscribed() but I want to be able to get all Listings where the user is subscribed.

I tried making a custom method on the Listing model to no avail. Here is what I tried

public function scopeSubscribed($query)
{
    $query->whereHas('user', function($q) {
        $q->subscribed();
    });
}

and using it like so

$listings = Listing::subscribed()->all();

Doesn't work. Any ideas?

29 Jan
3 years ago

Kryptonit3 left a reply on [L5.1] Event Listener Gets Instance Of Model Instead Of Event Itself

@Francismori7 did you figure this out? Apparently I am running in to the same issue. :\

24 Jan
3 years ago

Kryptonit3 started a new conversation PlexRequests - PHP Version (Laravel)

I must say, I love my Plex Media Server setup I got going. Movies, Shows, autodownloading etc. I am sure some of you like me have others who share your server and are always requesting content. I came across a MeteorJS app that handles requests and talks to CouchPotato and SABnzbd and others like it to start auto downloading. I wasn't terribly impressed with the admin panel and the level of control I have with it. I am re-implementing it with Laravel and PHP.

img

I'll post the public repo when I finish it and it can be a community thing open to suggestions, features, etc.

Any other Plex'rs out there?

Kryptonit3 started a new conversation TheMovieDataBase Package

I found a really nice TMDB integration but the authors repo wasn't version controlled or on packagist so I decided to make a Laravel package implementation of his code.

Check it out: https://github.com/Kryptonit3/TMDB-Laravel

27 Jul
3 years ago

Kryptonit3 left a reply on Auth::user() Returns Unexpected User

maybe this will work better?

public function isAdmin() {
    return ($this->status) true : false;
}
20 Jul
3 years ago

Kryptonit3 left a reply on DB RAW

try putting this before your $results query.

DB::statement(DB::raw('SET @prev=0,@rownum=0'));

so

DB::statement(DB::raw('SET @prev=0,@rownum=0'));
$results =
DB::select(
    DB::raw("
        SELECT utilizador_id, nome
        FROM (
          SELECT *,
                 IF( @prev <> utilizador_id,
                     @rownum := 1,
                     @rownum := @rownum+1
                 ) AS rank,
                 @prev := utilizador_id,
                 @rownum
          FROM (
            SELECT * FROM `anuncios`
            ORDER BY utilizador_id, rand()
          ) AS random_ads
        ) AS ads_ranked
        WHERE rank <= 2;
    ")
);

var_dump($results);
19 Jul
3 years ago

Kryptonit3 left a reply on [L5.1] Event Listener Gets Instance Of Model Instead Of Event Itself

in your handle method the event itself should be available with $event and the Client model should be available with $event->client.

But isn't this the purpose? To pass your Model to the event and then pass the model from the event to the listeners?

What are you trying to do exactly?

Kryptonit3 left a reply on Input::get("array") With Form Request

just make sure you append the items with an array in the name like

<input type="text" name="name[]" value="blah!" />

Then you can process them in the form request like this

public function rules()
{
    $rules = [
        // put your static input fields here
        'title' => 'required',
    ];
    // your arrays can be done like this
    foreach($this->request->get('name') as $key => $value)
    {
        $rules['name.'.$key] = 'required'; // you can set rules for all the array items
    }

    return $rules;
}

Kryptonit3 left a reply on My Search And Tags Not Working Because Of My Structure

This may work but it doesn't look right to me

return view($layout, $data)->withPosts($posts)->withVideos($videos);

try

return view($layout, compact('data', 'posts', 'videos'));

Kryptonit3 left a reply on Combine Fields For Checking

well that isn't going to work. I am sure you will have employees with either the same first name, middle name and/or last name so the unique validation rule would not work in this case. What it looks like you are doing is trying to get a unique composite key (can't remember but thought I read somewhere that Laravel doesn't support this).

With your current method if you do happen to have a record for an employee but you misspell their name then that becomes an issue.

You are better off creating some sort of searching method first, retrieve records that are LIKE what you are looking for, if they exist then edit, if not then create.

Kryptonit3 left a reply on Get Id

The value of Category will then be the category id. So no query required.

Kryptonit3 left a reply on LaraBin.com - It's Live!

hmm... I will look into it. Issue with that is that all guest comments will be as Guest so it would be hard to differentiate between multiple guests. But I guess people would just add a slight signature like

This is my comment

-K

Kryptonit3 left a reply on LaraBin.com - It's Live!

I will eventually implement a cookie that will allow you to edit/delete your bin as long as you still have the cookie.

Kryptonit3 left a reply on LaraBin.com - It's Live!

You may now post Bins as a guest!

Kryptonit3 left a reply on Get Id

you could perform a query to get the ID, but your best bet is to use the category id to begin with in the form you are getting this data from. If it is a dropdown select then make the value of the option the category id.

Kryptonit3 left a reply on LaraBin.com - It's Live!

You will soon be able to create a bin without having an account!

img

Kryptonit3 left a reply on Laravel 5 Validation Request, How To Handle Validation On Update?

Maybe @bashy was referring to an actual SQL query which you would indeed use a colon prefixed word to indicate an value to prevent SQL injections.

$results = DB::select( DB::raw("SELECT * FROM some_table WHERE some_col = :somevariable"), [
   'somevariable' => $someVariable,
 ]);

Kryptonit3 left a reply on Laravel 5 Validation Request, How To Handle Validation On Update?

Does it pretty much do the same thing? Seeing how rules with parameters list there parameters prefixed with a colon it seems that an additional colon would conflict with that. Would be curious to see something in the framework that shows how this additional colon on a rule with an existing colon would be processed.

Kryptonit3 left a reply on Php5-fpm Very High Cpu Usage

@NexPB I just looked at your site. Nice! From what I can tell, A LOT of the content can be cached. Are you doing any caching?

Also, are you using Nginx or Apache? A site like this would really benefit from an Nginx front-end that proxies requests to apache.

18 Jul
3 years ago

Kryptonit3 left a reply on Socialite - Without Creating User?

No, this is normally how you use Socialite. http://laravel.com/docs/5.1/authentication#social-authentication

This is just my method for handling the callback so it will work for guests who want to make an account, guests who have an account and just want to login, and users who want to either connect with the social network for the first time, or update their existing authorized token.

Kryptonit3 left a reply on Socialite - Without Creating User?

Just create the proper columns on the user table ( facebook_token ) and perform the oauth redirection and processing.

Here is how I process a socialite request with github for guests who do not have an account, and for logged in users who have not used socialite to register.

https://github.com/Kryptonit3/LaraBin/blob/master/app/Http/Controllers/Auth/Socialite/GithubController.php#L71-L77

Kryptonit3 left a reply on Php5-fpm Very High Cpu Usage

Definitely check out those 2 links. The debugbar is awesome. And make sure you are leveraging eager loading (N+1 will bog down an app quick).

Kryptonit3 left a reply on Php5-fpm Very High Cpu Usage

You would need some serious traffic to make the $20 a month plan worth it.

Kryptonit3 left a reply on Php5-fpm Very High Cpu Usage

Well, it appears as mysql is running hot so I would check your queries to see what can be optimized.

16 Jul
3 years ago

Kryptonit3 left a reply on Stripe Cards Getting Declined

With the stripe php api they have provided an easy way to catch a card declined error exception. On a card decline you could let the user know that it was declined, and if they are sure it is not an insufficient funds issue link them to a page with a method on how you can conditionally accept another method like paypal or something similar.

Kryptonit3 left a reply on TokenMismatchException

@opheliadesign the only problem I see with that is a TokenMismatchException isn't directly tied to an expired session. I have gotten them before for a number of different reasons.

But this is a good method for catching it. I personally would reword it to something along the lines of a general error

The form has expired, please try again. In the future, reload the page if it has been open for several hours.

Kryptonit3 left a reply on Where To Place Session Logic

@nathanrobjohn

by default, any data you add to the session stays the entire length of the session, you only have to add it once. If the session ever dies, so does the data. ( I think by default laravel sessions are 2 hours )

I am assuming you have a form on your site somewhere asking for this data and you post it to a controller method to persist it to the session.

What is the concern? Are you somehow manually carrying this data from each request?

If the concern is "Should i set these session values in my controllers?" then I would say it all depends. You are already handling the incoming request in your controller method, it shouldn't be an issue setting session data in the same request as processing the form.

Kryptonit3 left a reply on TokenMismatchException

@opheliadesign I ran into that exact scenario on a site I made for my company. Techs were leaving their order page up and tried to submit an order the next day and BAM, error. I then implemented a simple ajax request that runs every few seconds to a method on my controller that returns value of auth()->check() and if it ever returns false, a non-dismissable modal with a message and link to the login page automatically pops up.

Kryptonit3 left a reply on Eager Loading

Well, say you are in a loop. You have a User model, and a Profile model and a user hasOne Profile and a Profile belongsTo a User.

$users = User::all(); // 1 Query (say, you have 10 users)
// then in the blade
@foreach($users as $user)
    <p>{{ $user->profile->twitterUrl }}</p> // runs 1 query for each user in the collection to pull the profile data (so 10 queries)
@endforeach

In all, you ran 11 queries.

Now let's eager load the profile data

$users = User::with('profile')->get(); // 2 queries, 1 to grab all users, and 1 to grab all profile data
// then in the blade
@foreach($users as $user)
    <p>{{ $user->profile->twitterUrl }}</p> // runs 0 queries because we eager loaded the relationship
@endforeach

In all, you ran 2 queries.

And why use Eloquent over a manual DB select/join? The awesome ability to traverse relationships in an OOP style.