Roni

Roni

Member Since 5 Years Ago

WINNIPEG, MANITOBA

Experience Points
81,850
Total
Experience

3,150 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
881
Lessons
Completed
Best Reply Awards
7
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 17
81,850 XP
Nov
13
2 days ago
Activity icon

Replied to Does Mix Have Any Commands For Brotli Compression?

@stockholm thanks for pointing that out! I have to go back to that project and see what differences it makes. Have you used it? Would you be willing to share a comparison?

Oct
30
2 weeks ago
Activity icon

Replied to No Output From Laravel Mix

The other commands all actually use the bootstrap css as well. Essentially they are the same blade files. By separating the whole package I thought they might take advantage and give some options like tailwind. I think its a missed opportunity.

That being said theyve made it easy enough to write a preset command, that Im not sure why I just dont take a day and make my own.

Im also having issues with yarn, they changed the scripts to run npm even if you start out with yarn in package.json. And for some reason cross-env isnt installing properly.

Just a host of small annoyances, that took a couple of hours to figure out.

Oct
29
2 weeks ago
Activity icon

Awarded Best Reply on No Output From Laravel Mix

Dammit!

Thats annoying!

Once the laravel/ui package has been installed, you may install the frontend scaffolding using the ui Artisan command:

// Generate basic scaffolding...
php artisan ui bootstrap
php artisan ui vue
php artisan ui react

// Generate login / registration scaffolding...
php artisan ui bootstrap --auth
php artisan ui vue --auth
php artisan ui react --auth

The problem is if you use the default php artisan ui:auth which DOES show up in the command list... It uses bootstrap classes but NOT the bootstrap framework.

That command should be stripped out or overridden.

Activity icon

Replied to No Output From Laravel Mix

Dammit!

Thats annoying!

Once the laravel/ui package has been installed, you may install the frontend scaffolding using the ui Artisan command:

// Generate basic scaffolding...
php artisan ui bootstrap
php artisan ui vue
php artisan ui react

// Generate login / registration scaffolding...
php artisan ui bootstrap --auth
php artisan ui vue --auth
php artisan ui react --auth

The problem is if you use the default php artisan ui:auth which DOES show up in the command list... It uses bootstrap classes but NOT the bootstrap framework.

That command should be stripped out or overridden.

Activity icon

Started a new Conversation No Output From Laravel Mix

Just started a new default project of laravel with no changes and ran mix, and noticed no output was generated for the CSS file even though there is default CSS included with laravel.

Is this likely a localized bug, some weird cache? Or is something happening with laravel mix at the moment?

Oct
08
1 month ago
Activity icon

Started a new Conversation Transforming SQL Query To Eloquent

I'm trying to transform some API endpoints that use SQL to something more eloquent. Right now, I have a series of API's that all are built on SQL which makes them a bit brittle.

I have an example. In a search box I'm looking for parents or students who have "ex" in their name.

Here is the sql

SELECT
    s.last_name,
    s.first_name,
    r.title,
    g.first_name,
    g.last_name
FROM
    students s
    INNER JOIN guardian_student gs ON s.id = gs.student_id
    INNER JOIN guardians g ON g.id = gs.guardian_id
    INNER JOIN rooms r ON r.id = s.room_id
WHERE
    s.first_name LIKE "%ex%"
    OR s.last_name LIKE "%ex%"
    OR g.first_name LIKE "%ex%"
    OR g.last_name LIKE "%ex%"

Structure

student (belongs to a) room (has many) student

student (belongs to many) guardians (belongs to many) student

all relationships are standard

This will return 1-2 tuples depending on the number of the students legal guardians.

Is there a way, to add a where clause on subquery

Something like

Student::with('guardians')
->where('first_name', 'like' '%'.$searchTerms.'%')
->orWhere('first_name', 'like' '%'.$searchTerms.'%')

// some magic here that lets me also check the guardians names against the search terms <---

->get();

Thanks

Activity icon

Commented on Play With Confidence

Did you find that shortcut out? I know I saw it in a video years ago, but I can't find that either.

It's a bit counter intuitive, but the rerun command shortcut in my new version of phpstorm was not the re-run command shown here. Instead he's using the Main Menu > Run > Run command, which will oddly re-run the last "Run Context Configuration test" (the original test) regardless of where you currently are in the code.

Cheers.

Oct
04
1 month ago
Activity icon

Replied to Faker - Providers Added At Each Factory Call

@devfrey THANK YOU!

Also, as a side note, some/(many) of the providers localizations need some work, and/or your validation or DB constraints might be limited to only valid information or a subset of valid information, for example the Canadian postal code generation will generate invalid postal codes, though structurally correct. So if you are using faker to populate a passing test and it fails because the system needs a valid item. You can end up with false positive fails.

You can register your own faker providers to eliminate that issue and your solution of adding it to the app service provider was the key for me! So even though you do change the locale in your config, it sometimes won't be enough.

Cheers!

Sep
20
1 month ago
Activity icon

Replied to Adding Helper Files From A Package To A Laravel App

Damn ! it works!

I was including it in the service provider but you need to do it before you declare your class!


<?php

namespace LaravelTestingConcerns;

include_once ('funcs.php');

use Illuminate\Support\ServiceProvider as BaseServiceProvider;


class ServiceProvider extends BaseServiceProvider {

    public function boot()
    {
    
    }

    /**
     * Register any package services.
     *
     * @return void
     */
    public function register()
    {
    
    }
    
}

@talinon for the win!!!

Activity icon

Replied to Adding Helper Files From A Package To A Laravel App

Sadly no dice, I keep coming back to this and burning 20 min chuncks :( But I just can't figure out any combination of making this happen. I just want to include my global functions but from the package pushing into the app, not from the app side pulling in the package.

In the interest of time, I wimped out and just made a preset command to load my files in the right places and update composer.json. So lame, but at least it won't be a barrier to entry for others.

Activity icon

Replied to Adding Helper Files From A Package To A Laravel App

@talinon thanks for the tip and the article, I've been chasing this down from another angle, but notice at the bottom of the article there is a link to this:

https://github.com/laravel/framework/blob/6.x/src/Illuminate/Foundation/helpers.php

Notice these are in laravel/framework not in laravel/laravel yet they are globally active in laravel the laravel app, I'm trying to achieve the same thing.

Activity icon

Started a new Conversation Adding Helper Files From A Package To A Laravel App

When writing a package, I want to add two helper files to my laravel application.

Normally I'd just pull them in through composer to the proper namespace. Like this in a laravel App

Composer.json

The Following would pull functions in the app/Helpers/BaseHelpers.php into a global scope in the app namespace, and the functions in tests/test-helpers.php into the test namespace.

autoload": {
    "psr-4": {
      "App\": "app/"
    },
    "files": [
      "app/Helpers/BaseHelpers.php"
    ]
  },

"autoload-dev": {
    "psr-4": {
      "Tests\": "tests/"
    },
    "files": [
      "tests/test-helpers.php"
    ]
  },

However, if I'm writing a package and I want a file to be pushed into global scope of the test namespace in the project consuming it, how would you adjust the composer.json in the package?

Sep
13
2 months ago
Activity icon

Replied to How To Become Web Development Master?

Grasshopper,

Those answers looked too long. I'd suggest years in a monastery meditating and working on your patterns, katas and defeating all opponents! Well ... design patterns, code katas and just complete projects instead. Thats pretty much it, write lots of code, and finish what you start. Once you've done that for a while, this question will become meaningless.

Activity icon

Replied to Passport For Local API Requests

Thanks @belv3dere,

I'm trying to process this all, it's one of those issues that is so easy that it's in fact hard. If you or someone could look at my failing test to and let me know what, I could do to make it pass, it would be really helpful.

So, I have a clean install of laravel 6.0

I've installed passport as follows:

composer require laravel/passport
php artisan migrate
php artisan passport:install

php artisan make:auth

I've added HasApiTokens to User.php and Passport::routes();to AuthServiceProvider.php, I've also changed my config/auth.php to use passport for token authentication and finally added \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class, to kernel.php in the web middleware section. So for my use case it looks like I'm set up.

Now here are the tests and everything passes except one, which is holding me back from moving forward.

<?php

namespace Tests\Feature;

use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Laravel\Passport\Passport;
use Tests\TestCase;

class ExampleTest extends TestCase
{
    use RefreshDatabase;
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
    
    
    
    /** @test */
    public function it_has_oauth_clients_set_up() {
        
        $this->assertEquals(0, \DB::table('oauth_clients')->count());
        
        Artisan::call('passport:install');
        
        $this->assertEquals(2, \DB::table('oauth_clients')->count());
    }
    
    /** @test */
    public function non_protected_api_routes_are_accessible() {
        $this->getJson('api/ping')
            ->assertOk();
    }
    
    /** @test */
    public function secured_api_routes_are_are_not_accessible() {
        $this->getJson('api/secure/ping')
            ->assertUnauthorized();
    }

    /** @test */
    public function secure_api_route_can_be_accessed_by_authorized_users() {
        $user = factory(User::class)->create();
        Passport::actingAs($user);
        $this->getJson('api/secure/ping')
            ->assertOK();
    }
    
    /** @test */ //THIS IS THE TEST THAT FAILS
    public function test_actual_passport_implementation_of_user_hitting_api() {
        Artisan::call('passport:install');
        $user = factory(User::class)->create();
        $this->post('/login',[
            'email' => $user->email,
            'password' => 'password',
        ])

        //this assertion works, the user IS logged in and redirected.
            ->assertRedirect(route('home'));

    //however the middleware is NOT assigning a token to the user,
    // so I'm not sure how this is supposed to work!
    // The passport fake does work in the test above.
        
    dump(auth()->user()->token()); //should be something but it's null
    // unless I'm misunderstanding 
    // \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class
    // should be adding a token to the user session after each request
    }
    
}

Just in case someone wanted the api.php

Route::get('ping',function() {
    return response(['pong'=>'ok']);
});

Route::prefix('secure')->middleware('auth:api')->group(function(){
    Route::get('ping',function() {
        return response(['pong'=>'ok']);
    });
});

Any advice welcome. What am I missing on that last test?

Sep
12
2 months ago
Activity icon

Started a new Conversation Passport For Local API Requests

I'm starting a web app that looks like it could that it might be a really good use case for an actual app. Normally when working on web sites or apps that wont be served by making an actual app, when using vue components, I'd just use really basic token encryption. In some earlier work I've had them call routes in web.php directly.

However, in this project it's likely that after its running for a month or two the request will come to transition it to an app. That being said, is passport the right place to start to api authentication? Let me clarify a use case, it's medical app for use only by staff for patients.

In an example vue component, there may be a search for medical history or previous lists of treatment, physicians or anything, I can't really look at it the same way I would look at picking products from a vendor, so I'm assuming regular token auth is off the table. I could be wrong if someone knows more I'd appreciate the reasoning. What I'm looking for is a way for the Vue component to get that information from api endpoints, and still be secure.

When I say API endpoints, there is no CORS happening it's all in the same app. I'll also need to add/update records from vue equally secure. There won't be any public access to this information, no external registration. Only staff will be able to log in and access the data. There won't be any logging in using facebook / github / google etc...

So the main purpose of the ultra secured API is for the website vue components for now, (or in the future possibly an app) to communicate with the data layer.

Am I over thinking this? Is basic token authentication enough, is JWT or passport the right solution? Can anyone point to the best way to accomplish this setup. Oddly I've found laracasts pretty lacking in this area, and most tutorials focus on the CORS aspect without actually touching on simple API security.

Thanks in advance for any advice.

Jun
26
4 months ago
Activity icon

Replied to Adding Groups Of Assertions To Tests

@bobbybouwmann love that approach! Pulling in single use traits seemed like a good idea! I never got around it it and left everything as macro's as of my last approach. I'm not fond of that even though I love macro's it means I'm pulling in a lot, and I have no code completion and my TestCase file is huge and annoying to edit!

Also some of my macro's depend on other macro's which I hate, I need to find a really good re-usable testing paradigm for myself. The laravel eco-system has REALLY beefed up it's testing game which is super exciting.

I haven't tried it yet, but for example the illuminate/database/collection and illuminate/support/collection classes are the ones I've made the most macros on.

If I made my own TestCollection class with a few other methods that revolve around testing, is there a way to resolve all collections as TestCollections? Or perhaps just make a decorator class with my functions? What do you normally do when you want to add a series of tests to an existing object (in the vendor library)?

Activity icon

Replied to Adding Groups Of Assertions To Tests

@paul-a-byford

I love that you are jumping in on this one!!! It's complicated hence no answers :( However I'll read your link tonight and get back to you. I actually got pulled heavily into a full VueJS right after this (the next day) and since there was no traction here or stackexchange I let it go for a bit.

I feel like I could add a series of call a series of single use traits to my test case depending on the type of project I'm working on. Most of the time the macro concept works at the beginning, but as you build up an arsenal of really battle tested assertions it doesn't make sense to go back and redo them.

That would allow me to add code completion to some of the assertions. I find it helps me think them through a bit more. Most of the time I'm looking at a bullet list of tests I've worked out on paper and I'm not sure how I'm going to handle them all.

So I'll have some basics like

  • an example has saves to the database
  • an example redirects to the proper route when scenario 1 happens
  • an example needs a field etc...

Which are (*mostly) worked on (just the names of the tests) in advance often before I know what technology I'll use for the front end, blade, total vue, something in between. Since each of those work flows would require different tests, I want to just pull in the ones I'd need for that tech stack, assertViewHas vs assertVueComponentPropIs etc...

Some will still have to be macro's I may add them in a Service Provider. I'll be back in Laravel again in about 10 days, so I'll try and play around with a package or something solid before then.

Thanks again for the link, the idea and the contribution!

Activity icon

Replied to ErrorException: Trying To Get Property 'id' Of Non-object.

@otto09 if an answer solves your issue, you should mark it best and close the question. Cheers

Activity icon

Replied to Elegant Eloquent Where

Glad I could help :)

Jun
25
4 months ago
Activity icon

Replied to Mobile App

Do you have Plex Media Server? Or Air Player? Or any other movie player? Whenever Im travelling and don't want to depend on working wifi, I download the videos I want and upload them to my plex server as a tv series. Then I sync them to the device I'm travelling with.

Remember to purge them when you are done, they take up valuable space.

The same process can be done with any media app. Don't bug Jeffery, he does enough for us already.

Activity icon

Replied to ErrorException: Trying To Get Property 'id' Of Non-object.

You should post code, and this may not help, but in context the "$thing" object you are trying to get the id on is null. Or to clarify $something = $thing->id and $thingdoesn't have a value, therefore you can't reference id because if $thing is nothing, it has no parts or properties.

If it's not critical that $something needs to be defined you could always use the optional keyword.

$someting = optional($thing)->id;Won't blow up. But $someting will be null as well. This is a helpful write up from laravel-news https://laravel-news.com/laravel-optional-helper

Good luck

Activity icon

Replied to Elegant Eloquent Where

If you already have the project presumably $project and an auth()->user()you can normally just check against the relationship. @crash's answer shows you where you might put it. Remember you have the relationship that defines function members() you can always chain a condition on that, assuming a member has a user_id

$project->members()
    ->where('permission', 'write')
    ->where('user_id',auth()->id())
    ->exists()

HTH

Activity icon

Started a new Conversation Objects In Session With Methods

I found quite by accident that while writing a test to store and retrieve an object id, and I had actually (accidentally) stored a complete object on the session.

EDIT: After re-reading this once, some clarification:

  1. $this->topicis set up in the setup() funciton
  2. $this->submitNoExceptions()just runs the request against the endpoint I'm testing against and returns a TestResponse Object. It has not bearing on the actual question of the object in the session.

Here is the test in two parts

/** @test */
public function session_has_last_entered_object() {
    $this->submitNoExceptions()
        ->assertSessionHas('last_entered_type', Question::class);
    $this->assertTrue(session('last_entered_id')->is(Question::last()));
    

    //the second part

    $question = session('last_entered_id');
    $this->assertTrue($question->topic->is($this->topic));

    //will fail - part 3
    //$this->assertEquals($question->topic,$this->topic);

}

Of course it started wrong as initially I had $this->assertTrue(session('last_entered_id')->is(Question::last()->id)); however, after the error instead of immediately correcting it, it occurred to me (for this use case at least) there is no problem with any race condition and I could save myself one database call on the next request by simply accessing the session variable.

After looking at some searches the main drawback in this situation, was that it was going through some magic serialization and it was just data. You couldn't run methods off of the object. However it clearly is working as the object based on the "second part".

There is another follow up that I noticed. I tried modifying this to use assertEquals instead of the ìs()unction and it did fail. The difference was the "wasRecentlyCreated" property.

Some questions:

  1. Is it a terrible practice?
  2. Are you actually saving queries? Based on that part 3 it looks like it may not be.
  3. Can anyone weigh in on pro's and cons as to when this might be appropriate or what is hazardous.

Thanks

May
13
6 months ago
Activity icon

Started a new Conversation Does Mix Have Any Commands For Brotli Compression?

Just reading the tailwindcss docs, now that v 1.0 is out, and they refer to brotli compression. Is there a setting in laravel mix that enables brotli compression? Does anyone know how to roll this out to the server besides checking it off on cloudflare?