JohnRivs

JohnRivs

Member Since 4 Years Ago

Experience Points 95,950
Experience Level 20

4,050 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 956
Lessons
Completed
Best Reply Awards 37
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.

21 Feb
1 month ago

JohnRivs started a new conversation Relax The Caching On Https://laracasts.com/search

I know https://laracasts.com/series/build-a-laravel-app-with-tdd/episodes/29 is out already but it still doesn't show in https://laracasts.com/search Maybe set it to 1 day instead of 2+?

20 Jan
3 months ago

JohnRivs started a new conversation Disable/enable Certain WebPack Plugin Before/after Compilation

I'm using PurceCSS on certain assets but I don't want it to run for others. Is there a way to disable it after certain assets or enable it before certain assets?

Can't use 2 separate Mix files cause I need the results to be put in the same mix-manifest.json.

15 Oct
1 year ago

JohnRivs started a new conversation Bringing Vue-server-renderer And Laravel Mix Together.

I started reading vue-server-renderer's documentation and when I see the build setup (and other build setups from template repos) I instantly remember why I use Laravel Mix. Doing it yourself it's just a pain in the ass.

I'd love to see a series where we learn how to bring the simplicity of Laravel Mix into the build process in a server-side rendered Vue app.

SSR as a whole would be even better, but I feel like that'd be too much and the tweaks you have to do are covered in the docs. It's just the nasty build process that keeps me away from it. I do know about Nuxt and I'd rather not use it.

13 Feb
2 years ago

JohnRivs left a reply on Laravel Mix Takes So Much Time To Compile My CSS

Oh don't get me wrong. I'm not saying "Webpack is slow for what it does". In reality, my mix file has much more things.

This is my first time using Webpack so I wanted to know if this was the norm. Don't really wanna be waiting more than 5 seconds everytime I make a change, so I'll go back to good ol' Laravel Elixir.

JohnRivs started a new conversation Laravel Mix Takes So Much Time To Compile My CSS

I'm using Windows 10, ran npm install [email protected] --save-dev, copied the setup files and edited webpack.mix.js:

let mix = require('laravel-mix').mix;

mix.disableNotifications();

// Only so Webpack can even work..
mix.js('resources/assets/js/dummy', 'public/js');

mix.sass('resources/assets/sass/app.scss', 'public/css');

app.scss is just pulling less than 20 files. None of those files exceedes 100 lines of CSS.

I run npm run watch. 15 seconds to compile and then 7-8 seconds everytime I save a file. With Laravel Elixir, it used to take ~20ms to compile everything (not just styles) after saving a file.

Am I doing something wrong? Or is this the standard now?

02 Dec
2 years ago

JohnRivs left a reply on Do I Really Need To Use Protected $fillable If...

Create() is an eloquent method which case you need to set guarded or fillable.

And I'm gonna set $guarded to an empty array because I'm explicitly declaring which columns are being filled at the time of creation or update.

Any query builder and newing up the model and explicitly setting each object then call the save() method doesn't utilize eloquent.

Newing up an Eloquent model instance or fetching an existing model and calling the save method, most definitely utilize Eloquent. Every example I use in my first post uses Eloquent.

Also as I stated above forceCreate() will use eloquent but bypass fillable and guarded.

Or you can write protected $guarded = []; once and avoid prepending 'force' every time.

I meant it's a tool of many to help sanitize data.

Again, maybe I don't know what that word means, but fillable and guarded don't peform sanitation on the data. Those are not the ones responsible for escaping the input, for example. When it comes to the actual data being written to the database, it doesn't matter if you use them. They just do the white/blacklisting.

In a scenario where the payload only carries the 'name' field, this

class User extends Model {
    protected $fillable = ['name'];
}

User::find(1)->update($request->all());

will write the same thing in the database as

class User extends Model {
    protected $guarded= [];
}

User::create([
    'name' => $request->name
]);
01 Dec
2 years ago

JohnRivs left a reply on Do I Really Need To Use Protected $fillable If...

@milon Actually I think @mercuryseries might be right. The base Eloquent model comes with protected $guarded = ['*'];. Overriding it with an empty array will do just fine for me.

JohnRivs left a reply on Do I Really Need To Use Protected $fillable If...

@mercuryseries Yeah, I've seen them and Jeffrey doing it, that's why I made this thread. I wanted to confirm that I could also get rid of those properties with the way I do things.

JohnRivs left a reply on Do I Really Need To Use Protected $fillable If...

@milon ohh I can even get rid of $guarded too? Well that's even better. Thanks!

JohnRivs left a reply on Do I Really Need To Use Protected $fillable If...

@jekinney Could you clarify the second part?

As far as I know, $fillable doesn't perform any kind of sanitation. Maybe I understand something else by 'sanitation'. It only makes sure fields that are not declared in the array never hit the database, which what I'm manually doing each time I use create() and update(). So it seems kinda redundant.

JohnRivs left a reply on Do I Really Need To Use Protected $fillable If...

@ejdelmonico Thanks for your reply, but that's not what I'm asking for.

I wanna know if I can just do protected $guarded = []; since I don't pass $request->all() to create() or update(), because it bothers me going back to the fillable property each time I add a new column to the table.

JohnRivs started a new conversation Do I Really Need To Use Protected $fillable If...

If I always create and update Eloquent models like

User::create([
    'name' => $request->name
]);

and

$user = User::find(1);

$user->name = 'John';

$user->save();

but never

User::find(1)->update($request->all());

Do I need to use declare the fillable fields or can I get away with protected $guarded = [];?

22 Nov
2 years ago

JohnRivs started a new conversation Mixed Lessons And Series In /lessons

I wish series didn't show up in /lessons @JeffreyWay

  1. To me, it's kinda confusing, unnecessary and redundant to have both the lessons and series in this list. Specially when you have the same series link below the name of the lesson.

  2. New lessons in a series show up in the list (so still unwatched) but the series is still marked as complete, when it's not.

For reference:

14 Nov
2 years ago

JohnRivs started a new conversation Recursive Relationship With Scope

A user has a sponsor:

public function sponsor()
{
    return $this->belongsTo(User::class, 'sponsor_id');
}

A user has referrals:

public function referrals()
{
    return $this->hasMany(User::class, 'sponsor_id');
}

A user is considered capped when they have 2 or more referrals:

public function activeReferrals()
{
    return $this->referrals()->whereActive(true);
}

public function isCapped()
{
    return $this->activeReferrals()->count() >= 2;
}

A user can give points. By default, the sponsor will receive them, but if the sponsor is capped, I want the points to go to a sponsor's referral that is NOT capped. If all the referrals are capped, then it does the same thing with the level below (the referral's referrals).

If I go user by user making database calls for each one, it's gonna take a long time. How can I write a scope that makes recursive calls until it finds the first referral in the tree that's not capped?

This is what I'm trying to do:

21 Sep
2 years ago
18 Sep
2 years ago

JohnRivs started a new conversation Aliasing Routes For SEO Purposes

Ok so here's an assumption I have about URLs and SEO. There are sites with listings about something that could follow a very crud-esque pattern when it comes to the URL. For instance, /motherboards?year=2016&order=desc. However, that's not what I usually find in motherboard rankings, they're more like /best-motherboard-this-year or /best-motherboards-2016. I'm guessing this is a good practice for SEO purposes.

I used the word "could" because my developer eye sees what could be behind in CRUD terms. So, regardless of my assumption being right or wrong, how can I alias a route to another route, including its parameters?

13 Sep
2 years ago

JohnRivs left a reply on Was ->withInput() Replaced With Old()?

Now that I think about it, if I'm using form request objects, I'm not the one calling back()->withInput(). That should behind the scenes.

So, it only works when I use old().

JohnRivs left a reply on Was ->withInput() Replaced With Old()?

@tisuchi Does it work with Form Request Objects? Because I'm using one and tried back()->withInput(). No luck.

JohnRivs started a new conversation Was ->withInput() Replaced With Old()?

I'm looking for some confirmation here.

When a form has errors and the user is redirected back, if I wanna keep the data in the input fields, I used to use the withInput() method in my controllers. Now, it seems like that method is not needed, instead, I have to use value="{{ old('field_name') }}" on each input.

Is that how it works on Laravel 5.2? Is there a way to keep using withInput() without old()?

21 Jun
2 years ago

JohnRivs started a new conversation [Vue Router] History Mode With Hashbang Fallback?

I still don't know if you make the app work with pushState but fallback to hashbangs if the browser doesn't support pushState. Is this it?

    import Vue from 'vue';
    import VueRouter from 'vue-router';

    Vue.use(VueRouter);

    var router = new VueRouter({
        mode: 'hash',
        history: true
    });

On nginx: rewrite ^(.+)$ /index.html last;

About mode: 'hash' from the docs:

uses location.hash and listens to hashchange events. When you specify history: true when creating the router, it will fallback into hash mode in browsers that do not support the history API.
11 Jun
2 years ago

JohnRivs left a reply on Can't Make V-cloak Work Anymore. How To Force V-cloak To Stay Longer?

No.. I'm trying to use display: none in the end. I'm using background: red to make it really obvious. v-cloak is just an attribute that appears before the element is ready to be shown, regardless of the CSS.

10 Jun
2 years ago

JohnRivs started a new conversation Can't Make V-cloak Work Anymore. How To Force V-cloak To Stay Longer?

I don't know if it's just compiling too fast so it doesn't apply v-cloak or I'm severely overlooking something.

https://jsfiddle.net/mzcv1skk/

I don't see the red background that I imagine should appear for at least a frame. Is there a way to lengthen the compilation phase so I can get a hold of v-cloak while it's there?

08 Feb
3 years ago

JohnRivs left a reply on How To Make Sure The Front-end Is The Only Thing Able To Consume Your Own Api?

Mmm, my server is a DigitalOcean droplet, so I'm guessing it will have the same IP, but I was hoping to find a solution along the lines of authentication and/or tokens or something like that.

JohnRivs started a new conversation How To Make Sure The Front-end Is The Only Thing Able To Consume Your Own Api?

What are the best practices or guidelines when it comes to having an SPA or just a web app with some Javascript sprinkle? Is there a reliable way to make the back-end API only accept requests from the front-end?

In my case, I'm using Vuejs.

07 Dec
3 years ago

JohnRivs started a new conversation Using Vue-router With Laravel

I can't seem to get this working. I want to use Laravel as an API back-end and let vue-router handle the routing. Can someone share an example of vue-router replacing the Laravel's router role?

24 Nov
3 years ago

JohnRivs left a reply on Eloquent Static Methods: Not Declared With 'static' Keyword?

Eloquent (and many other classes found in Laravel) offer a Facade. It allows you to call methods on an object as if they were declared staticly. It acts as a proxy.

When you call orderBy on User, that method is being called on an actual object behind the scenes. It's syntactic sugar. In this case, your User model is extending Eloquent, which is where orderBy is found (it's not actually declared as a function; a magic method translates it to a query builder, which is in charge of building the SQL statement).

There 2 ways to go about it: - Add static constructors. Basically, you would define static functions on your User model that would act as constructor. Inside them, do whatever you need to do to the User object:

class User extends Model {
    public static function fromRequest(Request $request)
    {
        $user = (new static)->create([
            'name' => $request->name
        ]);

        return $user;
    }
}
Then, in a controller for example:
$newUser = User::fromRequest($request);
- Add query scopes. This lets you chain stuff to the query. For example, let's say you want to retrieve the tasks that are completed:
class Task extends Model {
    public function scopeCompleted($query)
    {
        return $query->whereCompleted(1);
    }
}
In your controllers:
$completedTasks = Task::orderBy('id')->completed()->get();
10 Nov
3 years ago

JohnRivs left a reply on Laracasts New Layout Is Awesome.

The columns in the footer stack one on top of the other on tablets. Is that intended?

JohnRivs started a new conversation Am I The Only One Experiencing This Delay On The Lessons Page?

It's been happening for a while now..

10 Oct
3 years ago

JohnRivs left a reply on 5656

Good talk.

08 Oct
3 years ago

JohnRivs left a reply on Form Model Binding Without HTML Facade

Any reason to not use the HTML Facade?

JohnRivs left a reply on [L5.1] Route-Model Binding For A Nested Resource?

Well.. that makes sense for Route::resource('bar', 'BarController'); only.. What I'm trying to return to my controllers when I visit /foo/qwer/bar/asdf is:

\App\Foo::where('something', $foo)->bar()->where('somethingElse', $bar)->first();

Where $foo equals 'qwer' and $bar equals 'asdf'.

JohnRivs left a reply on [L5.1] Route-Model Binding For A Nested Resource?

@pmall yeah but where do i get the id from? In the closure passed as a second parameter to Route::bind, I only get the first one (foo).

JohnRivs left a reply on [L5.1] Route-Model Binding For A Nested Resource?

Then how does Laravel know which Bar to retrieve? Cuz it has to be associated to Foo.

JohnRivs started a new conversation [L5.1] Route-Model Binding For A Nested Resource?

I got a few resources going on like this:

Route::resource('foo', 'FooController');
Route::resource('bar', 'BarController');
Route::resource('foo.bar', 'FooBarController');

I applied Route-Model binding correctly for Route::get('foo/{foo}', 'FooController@show');:

Route::bind('foo', function($value) {
    return \App\Foo::where('something', $value)->first(['column_a', 'column_B']);
});

I'm wondering, how am I suppose to do it for bar in foo/{foo}/bar/{bar}?

29 Sep
3 years ago

JohnRivs left a reply on Make Column Start From 1 Every January 1st?

I just noticed I didn't describe the problem correctly.

It's not like I need to insert a new row on Jan 1st and set the count to 1, cuz no invoice might be sent on that day. I need the count to start from 1 every year, so if I send the 421st invoice on Nov 15th, and the next one happens to be on Feb 10th, that one would have the value 1.

JohnRivs left a reply on Make Column Start From 1 Every January 1st?

Sorry, I said integer cuz I thought you believe I was using a number as a way to hide the actual value. It's an actual integer. Does it really matter though? It's something about invoices. Each one requires a number, and every 1st if January it needs to reset to 1.

JohnRivs left a reply on Make Column Start From 1 Every January 1st?

@pmall I need to store an integer.

So as @bestmomo suggested, whenever I'm going to insert a new row on that table, first I need to fetch the last one, check its timestamp to see if it's from the last year, and if it's not, i grab the the value from the count column, add 1 to it and save the number for the new row (the one being inserted).

Is there a way to avoid some of that?

JohnRivs left a reply on Make Column Start From 1 Every January 1st?

@bestmomo that's the first idea I had.. but I was hoping there was another way to do this so I could avoid making that check and fetching the previous record every time I insert a new one :/

Thanks!

JohnRivs started a new conversation Make Column Start From 1 Every January 1st?

Every January 1st, I need certain column to start counting from 1, so:

+-----+-------+
| id | count |
+-----+-------+
| 1   | 752   | # Dec 30th
+-----+-------+
| 2   | 753   | # Dec 31st
+-----+-------+
| 3   | 1     | # Jan 1st
+-----+-------+
20 Sep
3 years ago

JohnRivs left a reply on Which Of These Is You Favorite JS Framework To Use With Laravel?

@opheliadesign certainly not. I asked this a long time ago, I'm using VueJS nowadays. Both @JeffreyWay and @TaylorOtwell have helped greatly to make VueJS more noticed.

03 Aug
3 years ago

JohnRivs left a reply on A Smple Guide To Installing A Sublime Text 3 With Sidebar Icons

@Ruffles yeah.. that much i figured, since its what it says on the repo

im using material, with some of the settings found in that repo

JohnRivs left a reply on A Smple Guide To Installing A Sublime Text 3 With Sidebar Icons

@Twoopa I'm actually using the current Jeffrey's theme: https://github.com/christopherburton/Jeffrey-Way-Theme

Not sure it's 100% accurate, but it's really damn close. I don't have 100% like that either.

18 Jul
3 years ago

JohnRivs left a reply on Why Laracasts.com Is Not Open Source?

/me sits patiently until @JeffreyWay open sources Laracasts so I can publicly crucify for every violation of SRP.

08 Jul
3 years ago

JohnRivs left a reply on Where Should I Instantiate My Cart With PHPCart?

I'd create a service provider and create the instance there. Then I'd ask for it via constructor injection:

class MyController extends Controller {

    protected $cart;

    public function __construct(PHPCart $cart)
    {
        $this->cart = $cart;
    }

    public function index()
    {
        $this->cart->add([]);
    }

}
02 Jul
3 years ago

JohnRivs left a reply on Iron.io Queues With Laravel 5.1

It's not only gone from the docs, but also from the core of the framework.

01 Jul
3 years ago

JohnRivs left a reply on How To Deploy Laravel On OVH Perso

If that's a VPS (like Digitalocean for example), you can do it the old fashioned way using FTP or you can set up the repo in your server.

To emulate what platforms like heroku and stuff like that do, I create an empty bare repo. Let's say your app is served from /home/www/app. You'd have /home/www/repo/app.git, cd into it, giti init --bare and add the the url to that path to your remote branch in your local app (for example ssh://nameOfTheUser@yourDomainOrIP.com/home/www/repo/app.git).

Then you set up a hook to copy the app to /home/www/app after every push. So go to /home/www/repo/app.git/hooks and create a file called post-receive:

#!/bin/sh
git --work-tree=/home/www/app --git-dir=/home/www/repo/app.git checkout -f

If you need to add any other command, like composer install, add it to the file; a command per line.

Make it executable: chmod -x /home/www/repo/app.git/hooks/post-receive.

JohnRivs left a reply on Queue Scheduled Commands

What about the second one, Temporize?

And no, I think it needs to be every minute :(