ryanmortier

ryanmortier

Member Since 4 Years Ago

Experience Points 34,535
Experience Level 7

465 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 428
Lessons
Completed
Best Reply Awards 2
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.

13 Apr
2 months ago
10 Apr
2 months ago

ryanmortier left a reply on How Do I Pass 2 Arguments In Foreach ?

@ap3twe if a project belongs to a user then you need to create a relationship on the models so that this will work:

foreach ($users as $user) {
    //

    foreach ($user->projects as $project) {
        //
    }
}

ryanmortier started a new conversation Can I Omit PHP Docblocks If I Type Hint Parameters And Return Values?

Also, what's the purpose of docblocks? Is it just for IDE helpers and static analysis?

ryanmortier left a reply on How Do I Pass 2 Arguments In Foreach ?

foreach ($users as $user) {

    foreach ($user->projects as $project {
        //
    }
}

ryanmortier started a new conversation How Do I Read Source Code That Eventually Leads Back To An Interface?

Whenever I'm trying to figure out how something works and it leads back to an interface, I get lost.

For example, I was trying to figure out how the Str::plural() method works and if it supported non-Americanized English.

Step 1: Look up the Illuminate\Support\Str class. Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Str.php

Step 2: Find the plural() method. Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Str.php#L278-L281

Step 3: See that it's using a Pluralizer class so find that. Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Pluralizer.php

Step 4: Find the plural() method on the Pluralizer class. Done: https://github.com/laravel/framework/blob/5.8/src/Illuminate/Support/Pluralizer.php#L65-L74

Step 5: See that it's using Doctrine's Inflector class so find that. Done: https://github.com/doctrine/inflector/blob/master/lib/Doctrine/Inflector/Inflector.php

Step 6: Fine the pluralize() method on the Inflector class. Done: https://github.com/doctrine/inflector/blob/master/lib/Doctrine/Inflector/Inflector.php#L502-L505

Step 7: See that it's calling an inflect() method on a pluralizer object so try to find what the pluralizer object is. Done: It appears to be some type of instance of a WordInflector interface.

Now how do I go from here? I have no idea what the object is being passed that implements the WordInflector interface.

ryanmortier started a new conversation How Do You Know What To Test?

I'm starting to work through the "Let's Build A Forum with Laravel and TDD" series but one thing I'm wondering (not sure if it's answered later on in the series) is how do you know what to test? I can think of so many different things to test, how do you decide what to actually write a test for?

Also, bonus, how do people calculate the "test coverage" of their packages?

05 Feb
4 months ago

ryanmortier left a reply on Users Can Belong To A User And Have Many Users - How Do I Design This In The Database?

What's a large database? I don't see my users table ever growing over 25,000 users.

ryanmortier left a reply on Users Can Belong To A User And Have Many Users - How Do I Design This In The Database?

@billriess Never heard of nested sets but this seems to be exactly what I'm looking for.

ryanmortier started a new conversation Users Can Belong To A User And Have Many Users - How Do I Design This In The Database?

I'm building a feature where a user can belong to another user but they can also have many users.

For example a user can be one of four roles: Sales Manager, Regional Manager, Senior Consultant, Sales Representive.

A sales rep can belong to a senior consultant which can belong to a regional manager which can belong to a sales manager. A sales manager can have many regional managers which can have many senior consultants which can have many sales reps.

What would this look like in the database, would this look like in the database? Would this just be a user_id on the users table?

Secondly, I know I can use the hasManyThrough relationship to skip over the middle relationship, but what if I wanted to, for example, get all sales reps for a sales manager? Can I hasManyThrough a hasManyThrough relationship somehow?

Thanks.

ryanmortier left a reply on Carbon\Carbon Vs Illuminate\Support\Carbon?

@tykus That would indicate that a future release might remove the wrapper, right?

ryanmortier started a new conversation Carbon\Carbon Vs Illuminate\Support\Carbon?

if I'm using Carbon in my web app, should I:

a) implicitly use Carbon\Carbon as the laravel framework already includes it as a dependency or

b) use Illuminate\Support\Carbon or

c) explicitly composer require nesbot\carbon and use Carbon\Carbon?

a and b breakdown if Laravel ever removes it as a dependency

06 Dec
6 months ago

ryanmortier left a reply on What Is The Difference Between Multiple Workers Vs Multiple Processes?

So if I understand that correctly, I should only start a second worker if I have a different queue or driver or something along those lines?

If I want multiple "workers" on one queue I should instead just use one worker and multiple processes?

Thanks.

05 Dec
6 months ago

ryanmortier started a new conversation What Is The Difference Between Multiple Workers Vs Multiple Processes?

In Laravel Forge you can set up your queue workers but one of the options is the number of processes. What is the difference between setting up 2 worker daemons with 1 process vs 1 worker daemon with 2 processes?

09 Jul
11 months ago
13 Feb
1 year ago

ryanmortier left a reply on Allowed Memory Size Of 536870912 Bytes Exhausted

Didn't work unfortunately.

I've tried so many things. I've completely re-written it without using Leage\CSV as well and just streaming the CSV with PHP's built in functions and the same problem. I give up, ini_set('memory_limit', '2048M'); wins.

06 Feb
1 year ago

ryanmortier started a new conversation Allowed Memory Size Of 536870912 Bytes Exhausted

I just upgraded my homestead to the latest version and now a script I've been running is getting the error:

PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /home/vagrant/Code/app1/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 458


  [Symfony\Component\Debug\Exception\FatalErrorException]
  Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes)

The previous version of homestead worked fine and my production server works fine. Why am I suddenly getting this error?

I know I can just up the memory limit of PHP but I am trying to avoid that if I can because it was working fine before. Current memory limit is set to 512MB.

Here is the script I'm running, is there anything wrong with it?

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\Metric;
use App\Location;
use League\Csv\Reader;
use League\Csv\Statement;

class ImportMetrics extends Command
{
    protected $signature = 'import:metrics';

    protected $description = 'Import metrics from CSV';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        if (file_exists($path = storage_path('app/import.csv'))) {
            Metric::truncate();

            $locations = Location::all();

            $csv = Reader::createFromPath($path);
            $records = (new Statement())->offset(1)->process($csv);

            $bar = $this->output->createProgressBar(count($records));

            foreach ($records as $record) {
                $record = array_map('filter', $record);

                $metric = new Metric([
                    'product_code' => $record[7],
                    'product_group' => $record[3],
                    'product_subgroup' => $record[4],
                    'product_class' => $record[5],
                    'product_subclass' => $record[6],
                    'unit' => $record[11],
                    'previous_quantity' => number($record[16]),
                    'previous_mt' => number($record[39]),
                    'previous_50lb' => number($record[37]),
                    'previous_sales' => number($record[15]),
                    'previous_gp' => number($record[36]),
                    'current_quantity' => number($record[10]),
                    'current_mt' => number($record[40]),
                    'current_50lb' => number($record[38]),
                    'current_sales' => number($record[9]),
                    'current_gp' => number($record[30]),
                ]);

                $metric->location()->associate(
                    $locations->where('code', $record[0])->first()
                );

                $metric->save();

                $bar->advance();
            }

            $bar->finish();
        }
    }
}
17 Jan
1 year ago

ryanmortier left a reply on Work For Laracasts (Web Designer)

Glad to see Laracasts continue to grow. One of the best purchases/decisions I made for my career.

30 May
2 years ago

ryanmortier left a reply on How Would This Be Written In Blade?

In your controller:

return view('view.blade.php', compact('cat'));

In the view:

@foreach ($cat as $c)
    <li> {{ $c->name }}</li>
@endforeach
29 May
2 years ago

ryanmortier left a reply on Why Are Laravel's Package.json Dependancies Using Dev?

Hmm, that didn't really clear it up?

If you aren't publishing to npm, it technically doesn't matter which flag you use. However, I find it a good practice to use the "--save" flag for modules that affect the source code that you write. Then use the "--save-dev" flag for modules that are required for your compiler to function.

So, looking at Laravel's devDependencies, we see several of them affect the source code we write, for example: Lodash.

ryanmortier left a reply on How To Pass A Block Of Html Data To All Views

Why is your route returning HTML? You should be using views.

return view('index');

ryanmortier left a reply on How To Pass A Block Of Html Data To All Views

You're describing the basic functionality of blade templates? I don't understand.

ryanmortier started a new conversation Why Are Laravel's Package.json Dependancies Using Dev?

This file: https://github.com/laravel/laravel/blob/master/package.json

Why are all the dependancies in devDependencies rather than dependencies?

Are they assuming that you're commiting your compiled assets? Otherwise, when you deploy to production, you still are going to be doing npm install, right?

Should we be commiting compiled assets or no?

26 May
2 years ago

ryanmortier left a reply on Importing From Node_modules Is Different With Sass, Less, And Stylus?

Actually, I just learnt about Webpack's advanced resolver which works with sass, less, and stylus.

This works:

@import "~vuetify/src/stylus/main";

ryanmortier left a reply on Importing From Node_modules In Stylus With Laravel Mix

@groenroos You have one too many up directories.

Change it to ../../../node_modules

By the way, I just asked a similar question here: https://laracasts.com/discuss/channels/general-discussion/importing-from-node-modules-is-different-with-sass-less-and-stylus

Feel free to follow it to see if their is a better way to import stylus.

ryanmortier started a new conversation Importing From Node_modules Is Different With Sass, Less, And Stylus?

When using Laravel Mix, to import from node_modules using either sass, less or stylus, it's always different. How do I know what to use? The following works, but I'm not sure if the stylus import has a more succinct way to import from node_modules rather than chaning a bunch of ../

Sass

@import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";

Less

@import "bootstrap/bootstrap.less";

Stylus

@import "../../../node_modules/vuetify/src/stylus/main.styl";
19 May
2 years ago

ryanmortier left a reply on Database Fields: Nullable Or Not?

Change all optional database fields to be nullable

This is what you should really have done though. Why store empty strings in the database?

03 May
2 years ago

ryanmortier left a reply on Eager Loading $with On Modal

Thanks, I wasn't sure if it was possible or not but you answered my questions. I'll probably just end up specifically calling the with() or load() methods rather than creating an additional relationship.

ryanmortier started a new conversation Eager Loading $with On Modal

So I know you can use the $with property on a modal to always eager load that relationship with the Object. My question is how do I put additional constraints on that eager load?

Example of a modal:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Customer extends Model
{
    use SoftDeletes;

    protected $with = ['orders', 'products'];

So my question is, how can I do this:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Customer extends Model
{
    use SoftDeletes;

    protected $with = ['orders' => function ($query) { $query->withTrashed(); }, 'products'];

as this gives me an exception...

08 Jul
2 years ago

ryanmortier started a new conversation Why Does An Expired Session Re-authenticate Instead Of Show A Login Form?

If I have a session expiry set for 120 minutes (the default), if a user leaves their browser idle for over 120 minutes and then clicks a link on the page, their session appears to be regenerated rather than showing the user a login form again. How do I fix this behaviour to show the login form when the session has expired?

09 May
3 years ago
08 May
3 years ago

ryanmortier left a reply on Elixir Ccompilation Fails On New Page

@dradnan

npm install less@2.6.1

Worked for me, thanks!

ryanmortier left a reply on Elixir Ccompilation Fails On New Page

I fixed my problem by switching to SASS instead of LESS. Really don't have time to troubleshoot random shit like this.

ryanmortier left a reply on Elixir Ccompilation Fails On New Page

Same problem, was working two days ago not an issue. Nothing in the code repo has changed but now I can't gulp. Fails on the exact same file bootstrap/type.less

05 Feb
3 years ago

ryanmortier started a new conversation How Do I Access Data Inside An Instance Of A Component With JQuery?

I have a component and it's all contained and everything but I'm using bootstrap so when my form inside a model is hidden, I want to reset some of the data in the Vue component so that if the model is re-opened, the form (with v-bindings) is reset.

Example:

$('#modal').on('hidden.bs.modal', function () {
    // how do I access an instance of one of my components here so I can do: this.list = [];
});
04 Feb
3 years ago

ryanmortier left a reply on Authorization No Longer Works With An Array Of Arguments On The Controller Since Upgrading From 5.1 To 5.2?

Interesting, I believe I may have fixed my problem.

It appears it's important what order the arguments are in. This works:

SourceController.php

public function destroy(Record $record, Source $source, DeleteRequest $request)
{
    $this->authorize([$source, $record]);

    // do stuff
}

SourcePolicy.php

public function destroy(User $user, Source $source, Record $record)
{
    return false;
}

ryanmortier started a new conversation Authorization No Longer Works With An Array Of Arguments On The Controller Since Upgrading From 5.1 To 5.2?

In laravel 5.1 I used to pass two objects through the $this->authorize() method on my controller methods and it worked great.

Example:

routes.php

Route::delete('records/{record}/sources/{source}', ['as' => 'records.sources.destroy', 'uses' => 'SourceController@destroy']);

SourceController.php

public function destroy(Record $record, Source $source, DeleteRequest $request)
{
    $this->authorize([$record, $source]);

    // do stuff
}

SourcePolicy.php

public function destroy(User $user, Record $record, Source $source)
{
    return false;
}

Since upgrading to 5.2 though, authorization doesn't forbid people who should be forbidden from accessing the resource specifically when I'm sending an array of arguments.

I checked the trait method on the official repo and nothing has changed?

https://github.com/laravel/framework/blob/7f62d81acb2001faafb21a32544464ebfc92476c/src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php#L18-L23

    public function authorize($ability, $arguments = [])
    {
        list($ability, $arguments) = $this->parseAbilityAndArguments($ability, $arguments);

        return app(Gate::class)->authorize($ability, $arguments);
    }
10 Jan
3 years ago

ryanmortier left a reply on ReflectionException: Class Log Does Not Exist In /home/vagrant/Code/

@rishabswift thank you so much. I've been struggling with a Laravel 5.2 upgrade for the past week and this solved my issue. I'm now wrapping my strings in quotes in my .env file.

19 Oct
3 years ago

ryanmortier left a reply on What JavaScript Library Does Laracasts Use For Notifications

I know he uses Sweet Alert. I guess I was just trying to figure out if he found a way to modify sweet alert to show in a corner of if we was using somehting else.

ryanmortier left a reply on What JavaScript Library Does Laracasts Use For Notifications

Actually, are you sure it's Pusher?

If you open the console in dev tools. Type:

flash('test')

and you'll see the notification I'm talking about.

18 Oct
3 years ago

ryanmortier started a new conversation What JavaScript Library Does Laracasts Use For Notifications

I'm specifically talking about the corner notifications like in the bottom right hand corner, not the Sweet Alert notifications.

15 Oct
3 years ago

ryanmortier left a reply on Angular.js

Thanks, but I learn better with Jeffrey's magical voice soothing my ears.

ryanmortier started a new conversation Angular.js

Would love some courses on this framework.

24 Sep
3 years ago

ryanmortier left a reply on Different Rules For Different Routes

Why not use a different Request for each action?

Like so:

use App\Http\Requests\Admin\Grade\CreateRequest;
use App\Http\Requests\Admin\Grade\UpdateRequest;
use App\Http\Requests\Admin\Grade\DeleteRequest;
public function store(CreateRequest $request)
{
    //
}

public function update(Grade $grade, UpdateRequest $request)
{
    //
}

public function destroy(Grade $grade, DeleteRequest $request)
{
    //
}

ryanmortier left a reply on Different Rules For Different Routes

Why not use a different Request for each action?

Like so:

use App\Http\Requests\Admin\Grade\CreateRequest;
use App\Http\Requests\Admin\Grade\UpdateRequest;
use App\Http\Requests\Admin\Grade\DeleteRequest;

    public function store(CreateRequest $request)
    {
        //
    }

    public function update(Grade $grade, UpdateRequest $request)
    {
        //
    }

    public function destroy(Grade $grade, DeleteRequest $request)
    {
        //
    }

ryanmortier started a new conversation How Can I Inject Into A Form Request When Using Resourceful Routes And Route-model-binding?

I'm using resourceful routes (Route::resource()) and nested resourceful routes.

If I have a nested resourceful route defined like so:

Route::resource('customers.orders', 'OrderController');

And in a view I have a very simple form that consists of only a submit button and no input fields (to create an empty order) that hits {!! route('customers.orders.store', ['customers' => $customer->id]) !!}. Using method injection in the controller and route-model-binding, it gives me the customer object if I ask for it. How do I access this in a form request though? When I attempt to method inject the customer, I get an empty customer object.

21 Sep
3 years ago

ryanmortier left a reply on Laravel Elixir And Node.js Install Issues On Windows

It's not realistic for many of us working in corporate environments to change OS just because of a small issue. If I changed OS, I wouldn't be able to do a bunch of other things that the other operating systems lack.

@zhiyong no need to install VS2013, just install node with the binary from their website and then open PowerShell as administrator and run all your node stuff from PowerShell.