Talinon

Talinon

Member Since 3 Years Ago

Toronto

Experience Points 137,480
Experience Level 28

2,520 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 722
Lessons
Completed
Best Reply Awards 104
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.

20 Apr
6 days ago

Talinon left a reply on ExpectException() Doesn't Work When It Is Catched

expectException() will only return true if the exception thrown is not handled. In your case, since you catch it immediately, the test faIls.

Either change your store method to throw your exception without catching it, or go about your test in a different way.

I realize in this example you're just doing some trial and error, but what exactly do you want to test? What I gather, you don't want to allow Private Profiles to be able to hit the store method.

So - maybe you want to place that logic in middleware, and then test that the user gets denied.

Something like:

public function private_profiles_may_not_create_whatever() 
{

    $this->actingAs($privateProfileUser)->post('/', [])
        ->assertStatus(401);

}

Talinon left a reply on Why MySql Show Number Of Rows 2X After Adding Foreign Key

It shouldn't.. and I can't think of any reason why it would.

How did you go about adding the foreign key? Did you run a migration, or did you execute a MySQL command thru the interpreter?

If you ran a command, what was it, and what did it say for number of rows affected?

12 Apr
2 weeks ago

Talinon left a reply on 404 Not Found

$cat_name = categories::where('id', $category_id)->firstorFail();

You have this outside of your conditional check on whether$category_id is empty. So, if it is empty (or if the provided category id doesn't exist) then `firstOrFail()`` is going to end up returning a 404.

07 Apr
2 weeks ago

Talinon left a reply on PHPUnit Throws Error But Works When Specifying The Specific Test

You probably have the same test class name defined in another test file somewhere. This happens to me occasionally if I copy the boilerplate of a test class to a new file and forget to change the class name.

Talinon left a reply on Route Issue

If you run a php artisan route:list, you should see a GET route registered with a URI posts/{post}, which will be a route model binding for your PostController's show() method. So, when you try accessing posts/trashed, you are hitting your show method, and since no there is no Post resource with an id of trashed, you're getting nothing.

If you define your trashed route BEFORE the resource route, it should solve the problem.

31 Mar
3 weeks ago

Talinon left a reply on How To Catch A "Trying To Get Property Of Non-object Error" In Laravel

It looks like first() has no results, which means you can't access vendor_company on something that is non-existent.

Talinon left a reply on How To Catch A "Trying To Get Property Of Non-object Error" In Laravel

So, your record doesn't have a vendor_company, which means it can't access a property on something that is non-existent.

You need to check for that before trying to access the property, or perhaps you can make the optional() helper work.

Talinon left a reply on How To Catch A "Trying To Get Property Of Non-object Error" In Laravel

Hard to say without seeing any code. It could be anything. A common reason for this error regarding Eloquent might be you are trying to reference a property off a relationship that doesn't exist for your record.. but that is just a wild guess.

Talinon left a reply on How To Catch A "Trying To Get Property Of Non-object Error" In Laravel

Well, that's not a Laravel error, but a PHP error. You'll want to look for something that uses an object property accessor -> on something that isn't an object. Follow the stack trace to lead you to the culprit.

Talinon left a reply on How Do I Become Good At Programming

To quote Einstein:

If you can't explain it simply, you don't understand it well enough.

I'm not saying that you can't learn from reading documentation and code, but I think nothing beats a good teacher. Jeffrey Way is a talented teacher that has a method of explaining things in a way that makes things click. Some people respond better to different styles of learning. Some might excel during lectures, others might need visual aids, other might need things in print. If everything you've tried up to this point hasn't worked, I'd suggest one of the best things you could likely do for yourself is subscribe to Laracasts and watch the dedicated series on TDD.

A couple hours of videos of having someone explain things in simple ways will advance your skills much faster than trying to decipher other developer's (potentially) complex code.

Talinon left a reply on POST And ActingAs Testing Not Working

@damcclean There could be lots of reasons why the test fails. It could be that you don't have a post route defined for /settings, it would be because of failed validation, it could be because you're not returning a redirect response from your controller, or anything else wrong along the way.

What error message are you getting?

Have you dd() the contents of $response to see what message you're getting?

BTW - there is no point in re-assigning the $response variable like you have. You can simplify it by doing:

$response = $this->actingAs($user)->post('/settings', [
            'first_name' => 'John',
            'last_name' => 'Doe',
            'email' => '[email protected]'
        ]);
26 Mar
1 month ago

Talinon left a reply on Sentinel Role Problem

I'm not going to respond to every bewildering thing you've mentioned, just the one thing you decided to quote me and call me out on. Go educate yourself on controller actions:

https://youtu.be/MF0jFKvS4SI?t=360

Talinon left a reply on Sentinel Role Problem

@jlrdw It's not the same thing at all. I don't even know where to begin.

He is asking about middleware. Your whatever-you-call-it, appears to be a method on a controller. The concept of middleware is to prevent the stack from ever reaching the controller.

What the heck is Cln?? If I don't know, how is a novice developer supposed to know? They are just going to paste that in, and wonder why they get a Class not found error.

What is a indexbl? That'll just confuse the person even further.

Why are you using unconventional controller methods? It should simply be index() not indexSomeArbitraryStuff()

Why is user()->role returning some comma-delimited string? Is anyone going to understand that? I sure don't.

Why are you returning a string from a ternary, then evaluating a strict comparison against what you returned, only to return true or false? Just return the result of in_array()? Also, string comparisons are one of the leading causes of slow code.

Talinon left a reply on Sentinel Role Problem

@rostal You can assign middleware to route groups to handle user access.

Routes:

Route::group(['middleware' => 'admin'], function() {
    // admin-only routes
});

Route::group(['middleware' => 'moderator'], function() {
    // moderator-only routes
});

Admin Middleware:


   public function handle(Request $request, Closure $next)
    {

    // deny access if the user is not an admin
        if (!Sentinel::inRole('admin))
        {

        // redirect code

        }


        return $next($request);
    }

Moderator Middleware:

 public function handle(Request $request, Closure $next)
    {

    // deny access if the user is not an admin nor a moderator
    if (!Sentinel::hasAnyAccess(['admin', 'moderator']) {

        // redirect code

        }

        return $next($request);
    }

25 Mar
1 month ago

Talinon left a reply on Subtract Array Value

@vandan You can simplify this quite a bit:


$difference = Registration::where('id','=',$id)->sum('charges') -
            Pay::where('student_id','=',$id)->sum('amount');

Talinon left a reply on Using Mockery, But Original Method Still Being Called

@bwrigley Hmm, there is only 2 things that comes to mind.

My first thought, and probably the least likely, is make sure you have imported IntercomGateway into your test file, otherwise by default, you'll be mocking & binding Tests\IntercomGatewayinto the container and hence leaving your original implementation untouched.

My second guess would be that you're not resolving it properly from within your application code. Can you show the code where you actually resolve IntercomGateway and make the call to createUser()?

24 Mar
1 month ago

Talinon left a reply on How To Run A Decent SetUp() In Laravel Dusk

Try adding a void return type:

 public function setUp() : void

Talinon left a reply on Is There A Way To Persist Certain Tables Between Tests?

@alexgodbehere php artisan migrate --database=mytestingdatasename

Talinon left a reply on Is There A Way To Persist Certain Tables Between Tests?

You might want to consider using the DatabaseTransactions trait. You can seed your database once, and DatabaseTransactions will still roll back the test transactions at the end of the tests, but won't run the migrations; meaning your seeded data will persist thru the tests. The only thing you need to be mindful of, is you will need to manually run the migrations on your test database to bring them up-to-date when you make changes to your database structure.

22 Mar
1 month ago

Talinon left a reply on Where To Use Vue In Laravel

@kinsaw88 what you are referencing is a View component, which you would need to register as a component for Vue to mount.

Instead of trying to go into great lengths to explain, I would suggest watching the entire free series on Vue. You'll be taken by the hand and shown every step of the way.

https://laracasts.com/series/learn-vue-2-step-by-step

Talinon left a reply on How To Remove Item From Cart Through Session Laravel 5.6?

@mubeenali Did you write the original Cart code above, or are you editing an existing project?

Talinon left a reply on Using Mockery, But Original Method Still Being Called

There seems to be a problem with return types and previous versions of Mockery. Most likely because the version of Mockery you are using is based upon a PHP version that didn't support return types.

Talinon left a reply on How To Remove Item From Cart Through Session Laravel 5.6?

@mubeenali There is no short-cut to just remove it from the session - because how is your qty and prices supposed to update?

You need to pretty much do the same thing you're doing when you're adding to your cart.

Get the cart from the session, instantiate your Cart class with the session data, call a method that handles the remove logic, and then put it back into the session.

Talinon left a reply on How To Remove Item From Cart Through Session Laravel 5.6?

Unsetting the product from your Request object isn't going to remove it from the session.

It looks like you might want to add a remove() method to your Cart class, and then update the session?

Talinon left a reply on Using Mockery, But Original Method Still Being Called

Try removing the return type:

From:

public function createUser(User $user): void

To:

public function createUser(User $user)

Talinon left a reply on Using Mockery, But Original Method Still Being Called

Do you have final defined on your createUser() method in your IntercomGateway class?

Talinon left a reply on Using Mockery, But Original Method Still Being Called

Yes, you should get 'mocked' as a response. I'm not sure why you would get ``null`

I just tested it using the following, and I get 'mocked`

        $mock = \Mockery::mock('someclass')->makePartial();
        $mock->shouldReceive('createUser')->andReturn('mocked');
        $this->app->instance('someclass', $mock);

        $gw = resolve('someclass');

        dump($gw->createUser(new \App\User));        

Talinon left a reply on Using Mockery, But Original Method Still Being Called

@bwrigley You are still instantiating an instance of IntercomGateway directly in your test:

$gw = new IntercomGateway;

If you resolve it out of the container, it should work:

$gw = resolve(IntercomeGateway::class);

dump($gw->createUser(new \App\User));

Talinon left a reply on Using Mockery, But Original Method Still Being Called

Have you imported IntercomGateway in your test?

Talinon left a reply on Add Additional Login Condition.

I can see valid points on both sides of the argument.

It does seem odd to login in a user, only to turn around and log them out on an additional check. Maybe you (or some other team member) changes something to the related table structure/data which causes the check to break.. then your user stays logged in.

Make no mistake - overriding the login method like you have would work. The question really is, what is the best solution. I don't really see a big issue with what you've done. I've done something similar when I needed to handle a non-standard LDAP authentication login. As @snapey mentioned, just be mindful that you might need to re-evaluate your login logic when you go to upgrade your app.

Talinon left a reply on Mocking Class Doesn't Work

@ Glad that solved the issue. I'm sure we've all had that issue at one point in our career.

Please mark the thread as closed.

Talinon left a reply on Mocking Class Doesn't Work

Make sure you have Foo imported, you use the full namespace in your test. Otherwise it will be mocking Tests\Foo instead.. which I suspect is the issue.

Talinon left a reply on Mocking Class Doesn't Work

@yoeriboven Mocking a class within your test does not magically change your application code.

When you make your get request, your application routes it to your HomeController, which automatically resolves and instantiates a new instance of Foo. Your mocked object has no influence on this.

Instead, if you bound something into the service container which you use to resolve Foo, then you could swap that binding with your mock implementation.

For example:

/** @test */ public function it_mocks_bar() { $this->mock(Bar::class, function ($mock) { $mock->shouldReceive('action')->andReturn('Mocked value'); });

$this->app->instance(Foo::class, $mock);

$this->get('/');

}

Now when your application tries to resolve Foo, it will return your mocked object.

21 Mar
1 month ago

Talinon left a reply on Weird Template Or Render Function Not Defined

@shaqaruden Are you importing or requiring Vue? (in your main.js)

If you are using import, then you are getting the runtime build, which means you can't compile templates.

window.Vue = require('vue');

Talinon left a reply on Coming Soon Page While Admin Can Still Work In Backend

You could easily set up an IP exemption within your App\Http\Middleware\MaintenanceModeExceptions.php file.

Something like:

public function handle($request, Closure $next)
{
    
    
    if (!$this->exemptIps($request))
    {
    
        if ($this->app->isDownForMaintenance()) {
            throw new HttpException(503);
        }
        
    }

    return $next($request);
}


/*
 * Check to see if the HTTP request is from our exempt IPs
 * 
 * @return boolean
 * 
 */
private function ExemptIps($request)
{
    
    return in_array($request->getClientIp(), config('app.exempt_maintenance_ips', []));
    
    
}

Then add an array of IPs to your ``config/app.php`` (or whatever file you want)

Then you just need to code the admin backend to handle the artisan calls.

Talinon left a reply on Report Bug Function To Remote Database

I would suggest taking a look at bugsnag - bugsnag.com

They support laravel. You just apply your API key which they provide you, and your errors automatically get collected on their platform for your convenience.

They provide lots of management tools too, such as marking bugs and assigning them to team members, etc.

Talinon left a reply on Laravel Ajax - Put Request 500 Internal Server Error

@sunnyboy You would get around it by method spoofing, just like HTML forms. That is what the _method field does.

I'm not suggesting this is your problem, just something to test to rule out with trial & error.

Talinon left a reply on Catching 505 Request In App\Exceptions

You could check for the status code within the app/Exceptions/Hander.php

public function render($request, Exception $exception)
{

    if ($exception->getCode() == 505) {

        // caught

    }

    return parent::render($request, $exception);
}

Talinon left a reply on Session Not Persisting

Are your routes included in the web middleware? If not, the session will not start/work.

Try checking php artisan route:list to confirm

Talinon left a reply on Laravel Ajax - Put Request 500 Internal Server Error

If it works locally but not in your shared environment, it's possible your provider has configured the webserver to disallow some HTTP verbs.

If you're getting an HTTP 5xx error, and there is nothing within the Laravel log, then I would conclude it's being blocked at the server level and the request isn't even reaching Laravel.

As @jlrdw mentioned, try changing it to POST just to see if it goes thru.

You could also try sending something via Postman and see what response you get.

18 Mar
1 month ago

Talinon left a reply on Mock Error In PhpUnit Test

You are mocking EmailList, but still end up instantiating an object and passing it to your function. This ends up calling pluck() on an actual instance of EmailList, and not your mock.

Have you tried passing your mock instead?

 $actual = $this->sut->getDoNotEmailers($mock):

Talinon left a reply on Query Relationship Returns Wrong Values

@joshblevins what data type is your performance_rating field?

Talinon left a reply on Clean My Code Of \Log::

This might place you on the right track (at least for models):

https://laravel.com/docs/5.8/eloquent#events

Talinon left a reply on Query Relationship Returns Wrong Values

You are passing a string, change it to be numeric:

$q->where('performance_rating', '<', 80);

Talinon left a reply on Clean My Code Of \Log::

Any editor worth mentioning will have a "find & replace" feature. Just do a global search for "Log::" within your app/ directory, and clear them out.

Talinon left a reply on How To Manage Files In Database

@kisaw88 Yes, that is correct.

You just need to write the application logic to determine what the path will be, and persist the path to the database. That is a better alternative than storing binary pdfs directly into the database.

Talinon left a reply on Lumen Session Not Persisting On Every Request

@xxrockonxx I'm glad you got it figured out!

Talinon left a reply on How To Manage Files In Database

@You technically could store it within the database, with a binary BLOB type.

$table->binary('pdf');

But, I still wouldn't recommend doing it. Storing the PDF on the disk and referencing a file path would be a better practice.