phpMick

phpMick

Member Since 3 Years Ago

Experience Points 55,050
Experience Level 12

4,950 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 137
Lessons
Completed
Best Reply Awards 34
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.

05 Aug
1 month ago

phpMick left a reply on Best Practice To Preventing Admin Account Making A Requests!!

I think it's better to let them "mess up" the data, It will be a bit strange if they are trying to change things with the admin account and it doesn't work.

You could use seeders for your dummy data, maybe get them to reset every night?

Mick

26 Jul
1 month ago

phpMick left a reply on Match URL Containing Parameter.

Currently doing it like this:

fnmatch('/things/*/others',$urlArray['path']);

phpMick started a new conversation Match URL Containing Parameter.

Hi,

I want to check if my previous URL is like this: /things/1/others or /things/5/others

What is the best way to do this? Regular expression?

Cheers,

Mick

09 Jul
2 months ago

phpMick started a new conversation Encoding Ids

Hey,

All my URLs have their ids encoded using https://github.com/jenssegers/optimus but I'm just pondering, should I encode my ids everywhere, so that they can never be discovered using dev tools?

I guess I'm specifically talking about where they are passed to Vue components.

Cheers,

Mick

21 Jun
2 months ago

phpMick started a new conversation Should I Use An Accessor Or A Function?

I have a function on my tenant model which gets all users (home and guest, using two relationships).

Would you have this as a function or an accessor?

I quite like using an accessor, so that they look more like relationships:

$tenant->allUsers;

or

$tenant->allUsers();

Cheers,

Mick

13 Jun
3 months ago

phpMick left a reply on Pass Two Parameters To Policy Function.

Already tried that.

phpMick started a new conversation Pass Two Parameters To Policy Function.

Hi,

I'm sure I have struggled with this before.

This is what I originally had:

Policy:

public function store(User $user)

Call in form request:

return auth()->user()->can('store', User::class);

Now I want to add a second argument:

public function store(User $user, Tenant $tenant)

and I try to call it like this:

return auth()->user()->can('store', User::class, $this->tenant_id);

and I get:

Too few arguments to function App\Policies\UserPolicy::store(), 1 passed in 
/srv/app/vendor/laravel/framework/src/Illuminate/Auth/Access/Gate.php on line 481 and exactly 2 expected

What am I doing wrong?

Cheers,

Mick

11 Jun
3 months ago

phpMick left a reply on Query Builder To Collection Of Models.

Not sure if I should make these function or accessors?

phpMick left a reply on Query Builder To Collection Of Models.

Yeah, as soon as I had a coffee I got it:

$modelCollection = Report::hydrate($results->all()) ;

Cheers,

Mick

phpMick started a new conversation Query Builder To Collection Of Models.

I had just made some changes to my database and now the relationships are more complicated.

This means that to get $user->reports I am now using the query builder to retrieve the reports which were previously just a many-to-many:

 $results = DB::table('users AS u')
            ->select('r.*')
etc

This means that I am now getting a collection of stdClass instead of a collection of models. Is there a way to use a query to get a collection of models (in one db hit).

I tried using hydrate but it requires an array.

Cheers,

Mick

04 Jun
3 months ago

phpMick left a reply on Security Concerns.

So basically ensure that the correct validation is in place when the request is received.

phpMick left a reply on Multiple Users With Same Login Page

I think he is saying that should should add a column to your users table (in the example it is called teacher and populated with the value 1 if they are a teacher).

The relationship will then only return users who have a 1 in this column.

Might be better if you called the column 'type' then used 1, 2, 3 (obviously using constants ) for the teachers, students and admins?

Seems like a neat solution to me.

Mick

phpMick started a new conversation Security Concerns.

Hi,

I've just been thinking about a few things.

I have a users index (using a Datatable) which displays both home and guest users. Administrators can only edit home users.

I manage this by using a canAdmin() function which populates a hidden column in the Datatable. I use this row to enable/disable the edit buttons.

Is this a security concern? Could a malicious user use developer tools to: 1, change the hidden column, so that they can edit rows they don't have permission for? 2, amend what is in the POST, so that they can edit users that they don't have permission for?

Cheers,

Mick

30 May
3 months ago

phpMick left a reply on Session Data Lost After Redirect.

@davidpetrov thanks, great detective work.

I do indeed have some middleware which ensures a valid tenant is selected.

In this instance I was selecting -1 to signify 'All Tenants'. My middleware was failing to find a valid tenant with this id, so it sets it to be the users 'home tenant' (and overwriting the -1 I had put in session with 2).

:-)

phpMick started a new conversation Session Data Lost After Redirect.

I'm pretty sure I have seen this before but I can't remember how I solved it.

My session data is getting lost when I do a redirect.

 if($request->tenant ==="-1") {//all tenants selected
            session()->put('selectedTenant',"-1");
}


return redirect(url()->previous());

I tried adding this but It didn't help:

$request->session()->save();

In this function I can check and the session variable is set correctly. If i stop the code after the redirect, the session has restored to it's previous value.

Mick

05 Apr
5 months ago

phpMick left a reply on Learning Laravel And Feeling Overwhelmed

Have you tried watching the videos on here?

Maybe start with something like this:

https://laracasts.com/series/laravel-from-scratch-2018

That's how I did and I found it pretty easy to pick up (credit to Jeff, not my intelligence).

Cheers,

Mick

28 Mar
5 months ago

phpMick started a new conversation GUI For Assigning Many-to-many?

Hi,

What does everyone for a GUI for assigning many-to-many relationships?

I have a user and I want to assign them to user groups (they could be in 100) on the user edit page.

I'm thinking a searchable list containing groups (could be a few hundred) on the left, then a list on the right which hold the groups that this user belongs to. Then some buttons to add and remove.

Doesn't sound great but I can't think of anything better?

Cheers,

Mick

27 Mar
5 months ago

phpMick started a new conversation How Should I Be Using Select2

Hi,

How should I be importing Select2?

Just link to the js and css file?

Or should I be using npm and my webpack.mix.js?

Cheers,

Mick

22 Mar
5 months ago

phpMick left a reply on Add Additional Login Condition.

So what happens if something goes wrong in authenticated?

Isn't it possible that they could be left logged in?

phpMick left a reply on Add Additional Login Condition.

Sorry but I don't agree. The user should never be logged in, if they do not have access to the system.

The extra check should be in login() and should fail without logging them in.

Mick

phpMick left a reply on Add Additional Login Condition.

No. I don't want to do this, their login should fail and they should never be allowed to login.

I think I have it now:

 public function login(Request $request) {

        $credentials = $this->credentials($request);

        // Get the user login
        $login = $credentials[$this->username()];

        //Check if that login exists
        if(User::where($this->username(), $login)->count() > 0 ) {

            if(doMyExtraTest()) { 

        if(Auth::attempt($credentials)) {

        //etc

               }
          } else {

         throw ValidationException::withMessages([
                $this->username() => ['Failed additional test.'],
            ]);
    }

phpMick left a reply on Add Additional Login Condition.

It's looking like I do the additional check by adding a login() method to my LoginController.

I'm just not sure how to return the correct message.

21 Mar
5 months ago

phpMick started a new conversation Add Additional Login Condition.

Hi,

I want to add an additional login condition the 'proper' way.

I know the docs show how to check additional fields in the users table but I want to do a check on a different table:

My users table has a tenant_id which is a foreign key to the tenants table.

When a user attempts login, I want to retrieve their tenant and confirm that it allows logins of this type.

How should I be doing this?

Cheers,

Mick

19 Mar
5 months ago

phpMick left a reply on Delete Please.

He is a genius isn't he. :-)

Typically it started working after I posted. I have no idea what was wrong.

phpMick started a new conversation Delete Please.

Delete please.

04 Mar
6 months ago

phpMick left a reply on Testing That The Log Record Has Been Written.

Or, it was a poorly written question :-)

That's working now, thanks. I had this, why didn't it work?

  Log::shouldReceive('info')
        ->once()
        ->with('User created: '.$user->id);

Cheers,

Mick

phpMick left a reply on Testing That The Log Record Has Been Written.

Yes @ohffs I guess that is what I want (test that the calls have happend). I have been tasked with retrofitting logging to an application and I always try and start a task with failing tests and then fix them.

phpMick started a new conversation Testing That The Log Record Has Been Written.

Hi,

How can I test that a record has been written to my log file?

I am just using the standard Laravel logging?

Cheers,

Mick

25 Jan
7 months ago

phpMick started a new conversation Get One To Many Objects For A Many To Many Relationship.

I have users who have a many-to-many with groups. Groups have many reports.

How can I get all reports, for all groups which a user belongs to?

So I can do something like this:

auth()->user()->groups->reports

instead of cheating and just doing a select :-)

Mick

29 Nov
9 months ago

phpMick left a reply on How To Downgrade Bootstrap Version To 3.3.7 In Laravel 5.6?

@NULIMITZ - I tried this but I get:

File to import not found or unreadable: bootstrap-sass/assets/stylesheets/bootstrap
17 Aug
1 year ago

phpMick left a reply on Is There Any Drag-and-drop Studio/builder For Laravel?

Sound to me like you are not a coder, +1 for Wordpress.

phpMick left a reply on Best Datatable Plugin For Laravel ?

Yes, this is brilliant, I use it in every project:

https://datatables.net/

16 Aug
1 year ago

phpMick left a reply on Code Cached In EventSubscriber?

Stopped and started the queue worker, looks like that does it.

phpMick started a new conversation Code Cached In EventSubscriber?

Hi,

Can anyone see how the code would be cached in an Event Subscriber?

I am adding Logging and it is not appearing. Did a reboot (laptop and Homestead) and it started working.

I did also try a cache:clear and dump-autoload but it didn't work.

Am I going mad(der)?

Mick

09 Aug
1 year ago

phpMick started a new conversation Event Subscribers

Hi,

I am currently trying to use an Event Subscriber instead of separate Listeners.

Do I still need to create separate events? I guess so.

Can I use ShouldQueue in there?

Cheers,

Mick

08 Aug
1 year ago

phpMick left a reply on How To Use Dependency Injection In A Class With Static Functions?

Then pass the service to the function, or create it in the function?

phpMick left a reply on How To Use Dependency Injection In A Class With Static Functions?

Yeah, the class is never instantiated, so the constructor will never fire and $this->service will never be set.

What are you trying to achieve?

phpMick left a reply on How To Use Dependency Injection In A Class With Static Functions?

Surely $this does not exist, because you haven't created an instance?

07 Aug
1 year ago

phpMick left a reply on Pluck From A Collection Of StdClass

Actually, this is better:

‌‌$results->implode('id',',');

phpMick left a reply on Pluck From A Collection Of StdClass

Muppet:

$results->pluck('id')

phpMick started a new conversation Pluck From A Collection Of StdClass

I am trying to do this without iteration:

I have a collection of standard classes:

$results = {Illuminate\Support\Collection} [3]
 items = {array} [2]
  0 = {stdClass} [2]
    id = 1
    name = "home"
  1 = {stdClass} [2]
    id = 2
    name = "other"

I just want a comma separate string, containing all the ids of the stdClasses?

Thanks,

Mick

phpMick left a reply on Developing Without A Local VM.

No, I am using a company laptop.

It would be easy if it was mine and I may end up buying my own laptop but I'm trying to avoid that.

phpMick left a reply on Developing Without A Local VM.

Thanks @martinbean

This is what they have suggested, but I'm remote and don't want to be constantly connected to a VPN.

I love having a local development environment and that I don't need to be on a network.

phpMick started a new conversation Developing Without A Local VM.

Hi,

I am currently developing using Homestead but is looking like I will have to move away from this because I can no longer have local VMs (company policy).

What is the best alternative? I really like the ability to develop locally, without being on a network.

Cheers,

Mick

phpMick left a reply on Private Method Injection In A Trait

And, is there actually any benefit of doing this over:

$optimus = new Optimus;

phpMick left a reply on Private Method Injection In A Trait

What I want to do is this (just like you would in a controller):

namespace App\Traits;

use Jenssegers\Optimus\Optimus;

trait myTrait{

public function getRouteKey()
    {
        return $this->encodeId();
    }


private function encodeId(Optimus $optimus)
    {
        $encoded = $optimus->encode($this->getKey());

        return $encoded;

    }

}

That doesn't work, so instead I am doing this:

$optimus = app()->make('Optimus');

Is there a better way to do this?

Mick

06 Aug
1 year ago

phpMick left a reply on Private Method Injection In A Trait

I don't see that you need anything else.

I just need to know if it possible to get the $thing created automatically like this.

The code that calls it is:

 public function getRouteKey()
    {
        return $this->doit();
    }

This would work OK for a controller method, it is just not working because it is in a trait.

Thing is actually Optimus:

https://github.com/jenssegers/optimus

I have created a service provide, exactly as they describe (the only difference being that their method is in a controller):

<?php

namespace App\Providers;

use Jenssegers\Optimus\Optimus;
use Illuminate\Support\ServiceProvider;

class OptimusServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->singleton(Optimus::class, function ($app) {
            return new Optimus(1580030173, 59260789, 1163945558);
        });
    }
}

I could just ```new`` up the Optimus instead but I am trying to avoid that.

Mick

phpMick started a new conversation Private Method Injection In A Trait

Can I do this in a trait? If so how?

This is what I want to do:

private function doIt(Thing $thing)

I get this error:

 Too few arguments to function App\Models\User::doIt(), 

Thanks,

Mick