phpMick

phpMick

Member Since 4 Years Ago

Experience Points
55,220
Total
Experience

4,780 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.

Level 12
55,220 XP
Oct
29
2 weeks ago
Activity icon

Replied to Dependency Injection Constructor Parameter.

This is the problem now. I am trying to mock the queue by doing this (in a test):

app()->instance(StorageQueue::class,$mockQueue); //swap the fake one for the real one

This works when I inject it (can't use the constructor parameter):

public function processQueue(QueueInterface $queue)

but it doesn't work when I create it with the app() helper (can use a constructor parameter):

$queue = app()->makeWith(QueueInterface::class,['queueName' => env('QUEUE_NAME_IN')]);

This creates a 'real' object instead of using the mocked one.

Oct
25
3 weeks ago
Activity icon

Replied to Dependency Injection Constructor Parameter.

Yeah @tykus you have spotted the problem.

Basically I have two queues, one for messages in and one for messages out.

In QueueController->processQueue:

public function processQueue(QueueInterface $queue)

I am reading messages from the in queue.

I also use StorageQueue to send message to the out queue:

$queue = app()->makeWith(QueueInterface::class,['queueName' => env('QUEUE_NAME_OUT')]);

Maybe I need a different approach?

Mick

Activity icon

Started a new Conversation Dependency Injection Constructor Parameter.

Hi,

I have this in my controller:

public function processQueue(QueueInterface $queue)

I need to pass a parameter to the constructor:

public function __construct($queueName)

The class is registered in AppServiceProvider:

public function register()
    {
        $this->app->bind(QueueInterface::class, StorageQueue::class);
    }

How can I pass the constructor parameter when I inject the dependency?

Mick

Aug
05
3 months ago
Activity icon

Replied to 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

Jul
26
3 months ago
Activity icon

Replied to Match URL Containing Parameter.

Currently doing it like this:

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

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

Jul
09
4 months ago
Activity icon

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

Jun
21
4 months ago
Activity icon

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

Jun
13
5 months ago
Activity icon

Replied to Pass Two Parameters To Policy Function.

Already tried that.

Activity icon

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

Jun
11
5 months ago
Activity icon

Replied to Query Builder To Collection Of Models.

Not sure if I should make these function or accessors?

Activity icon

Replied to Query Builder To Collection Of Models.

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

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

Cheers,

Mick

Activity icon

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

Jun
04
5 months ago
Activity icon

Replied to Security Concerns.

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

Activity icon

Replied to 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

Activity icon

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

May
30
5 months ago
Activity icon

Replied to 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).

:-)

Activity icon

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