phpMick

phpMick

Member Since 3 Years Ago

Experience Points 53,870
Experience Level 11

1,130 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 33
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.

05 Apr
1 month 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
1 month 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
1 month 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
1 month 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
2 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
2 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 Session Helper Not Working

Hi I am trying to use the session helper in a service class and it isn't working.

I thought these were global helpers?

I'm just trying to do this:

session()->has('token')

It works in a Controller but not when I try in a class which has the namespace namespace App\SomeService\Something;

It's not really a problem because I can use a Facade but I just wondered why it wasn't found.

I'm getting:

Call to undefined function App\SomeService\Something\‌‌sessi

Cheers,

Mick

04 Mar
2 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
3 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
5 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
9 months 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
9 months 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
9 months ago

phpMick started a new conversation Event Subscribers

Hi,

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

Can I use ShouldQueue in there?

Cheers,

Mick

08 Aug
9 months ago

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

Then pass the service to 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
9 months 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
9 months 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);
        });
    }
}

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

phpMick started a new conversation How To Modify A Trait In A Composer Package.

Hi,

What is the proper way to do this?

I am using https://github.com/Propaganistas/Laravel-FakeId but I want to modify the trait in it.

Clearly I should not be modifying the package in my vendor directory, how should I be doing this?

Thanks,

Mick

27 Jul
9 months ago

phpMick left a reply on Issue With Vue - Inline-template Components Must Have Exactly One Child Element.

Exactly, you just need to wrap a div around your entire template:

<template>
    <div>

        ///existing code in here

    </div>
</template>

25 Jul
9 months ago

phpMick left a reply on Manually Populate Old() Array.

Hmm in my things create method, I create a new thing, to pass to my view. I reckon I can check the session and populate it with the remembered fields....

phpMick left a reply on Manually Populate Old() Array.

Here is a bit more detail:

1, things.create view - the user presses the + button to add a group. 2, the form is then submitted (POST) to my RedirectController this is where the form fields are placed in the session, then the user is redirected to the groups create page:

public function RedirectWithReturn(Request $request,$redirectTo){

        $previous = URL::previous();

        session(['returnURL' => $previous]);
        session(['savedForm' => $request->all()]);

        return redirect()->route($redirectTo);
    }

I now have in the session, the page which I should return to, after adding a group and the old form data.

3, the user now goes to the groups create page, where they populate a form, which has all the usual validation to store a new model.

4, when the group has been successfully created, the user is redirected back to the create thing page and their old input is used to populate the form fields.

So, I get that withInput() will redirect with the fields but it will get lost somewhere in this process. I need to store the fields manually.

Mick

phpMick left a reply on Manually Populate Old() Array.

@36864 I don't think that will work either. I don't want to redirect with the input, I want to save the input (which I am already doing in the session), then use it, when I come back to the 'things' create page.

phpMick left a reply on Manually Populate Old() Array.

Great, I was hoping for an answer which didn't involve redesigning my entire application.

phpMick started a new conversation Manually Populate Old() Array.

Hi,

1, I have a form (for adding 'things') which has a + button on it, to add a 'group'.

2, When this button is clicked, I wish to redirect to another form, so that the user can add a 'group'.

3, When the 'group' has been added, I redirect back to the 'thing' create form, so that the user can continue. I want the form to remember the fields which they have already populated.

I have got most of this working, by sticking the populated 'thing' fields in the session, now i just need to reload them, when I get back to the create 'things' page.

I was hoping to sneak them into the '''old()''' array, this way my Blade templates will work without making them more complicated.

Does this make sense and does anyone know how I can do it?

Cheers,

Mick

18 Jul
10 months ago

phpMick left a reply on How To Pass An Array As A Prop?

nope:

htmlspecialchars() expects parameter 1 to be string, array given

phpMick started a new conversation How To Pass An Array As A Prop?

Is this correct?:

<agreements-selector 
                                           :selected-agreements='{{ json_encode($groupingRule->agreement_ids)}}'>


I'm sure I have done this before and didn't have to use json_encode?

agreement_ids is cast to an array in the model.

Thanks,

Mick

12 Jul
10 months ago

phpMick left a reply on Communication Between Components.

Cheers,

I think I did option 1 last time and I think it's the best answer for my current application. It's pretty simple and I just want to pass an array from one to the other.

phpMick started a new conversation Communication Between Components.

Hi Team,

What is the best way to communicate between two components on the same level?

Cheers,

Mick

06 Jul
10 months ago

phpMick left a reply on Key Value Pair Editor.

Yes, clearly it can be done in many ways. I was wondering if anyone had done anything similar.

phpMick left a reply on Key Value Pair Editor.

I was wondering more about the user interface, I was thinking maybe create a Vue component.

phpMick started a new conversation Key Value Pair Editor.

Hi,

Has anyone done anything like this? I want the user to be able to enter key value pairs like name=test

Cheers,

Mick