phpMick

Experience

52,220

32 Best Reply Awards

  • Member Since 2 Years Ago
  • 136 Lessons Completed
  • 2 Favorites

18th July, 2018

phpMick left a reply on How To Pass An Array As A Prop? • 3 days ago

nope:

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

phpMick started a new conversation How To Pass An Array As A Prop? • 3 days ago

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

12th July, 2018

phpMick left a reply on Communication Between Components. • 1 week ago

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. • 1 week ago

Hi Team,

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

Cheers,

Mick

6th July, 2018

phpMick left a reply on Key Value Pair Editor. • 2 weeks ago

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. • 2 weeks ago

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. • 2 weeks ago

Hi,

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

Cheers,

Mick

28th June, 2018

phpMick left a reply on Homestead: "ETXTBSY: Text File Is Busy" • 3 weeks ago

Has anyone resolved this?

I have tried with --no-bin-links and downgrading npm and am still getting the problem.

phpMick started a new conversation Laravel Mix On Docker: ETXTBSY: Text File Is Busy • 3 weeks ago

I am trying to run Laravel Mix on my Docker container.

I have managed to install the latest versions of npm and node (thanks Laradock).

Now when I try and run npm install I get lots of these:

npm WARN rollback Rolling back [email protected] failed (this is probably harmless): ETXTBSY: text file is busy, unlink '/srv/app/node_modules/express/package.json.3619593601'
npm WARN rollback Rolling back [email protected] failed (this is probably harmless): ETXTBSY: text file is busy, unlink '/srv/app/node_modules/express/node_modules/array-fla
tten/package.json.2934324270'

node:v10.5.0

npm:v6.1.0

Windows host.

Guest is: Linux 2369f4b16e52 4.9.93-boot2docker #1 SMP Thu May 10 16:27:54 UTC 2018 x86_64 GNU/Linux

Is anyone else doing this?

Mick

26th June, 2018

phpMick left a reply on Laravel Mix On Docker Container. • 3 weeks ago

I almost have this working now, but when I try: npm run dev I get:

module.js:549
    throw err;
    ^

Error: Cannot find module '../'

phpMick left a reply on Laravel Mix On Docker Container. • 3 weeks ago

I think I will use a separate image for this task. I can then use one which will use an image which has node already installed.

22nd June, 2018

phpMick started a new conversation Laravel Mix On Docker Container. • 4 weeks ago

Hi,

Does anyone have Mix running on Docker?

I have install Node and NPM but when I try npm run dev I get:

module.js:478
    throw err;
    ^

Error: Cannot find module '../'
    at Function.Module._resolveFilename (module.js:476:15)


Thanks,

Mick

19th June, 2018

phpMick started a new conversation How To Set Items As Selected In A Multi-select? • 1 month ago

I have a multiselect:

<select class="tagSelector" name="useGroups[]"  multiple="multiple">

                        @foreach($userGroups as $userGroup)
                            <option value="{{$userGroup->id}}}" selected>{{$userGroup->name}}</option>
                        @endforeach
                    </select>

I have a collection of items which should be selected. how do I set them?

Thanks,

Mick

12th June, 2018

phpMick started a new conversation Phpunit.xml Is Ignored After Moving To Docker. • 1 month ago

I have just swapped from Homestead to Docker and my phpunit.xml settings are no longer working. The values from my .env are being used instead.

How can I troubleshoot this?

Thanks,

Mick

phpMick started a new conversation Hierarchical Data Structure For Multiple Parents. • 1 month ago

Hi,

I was using a nested set (https://github.com/lazychaser/laravel-nestedset) but now we have a new requirement where the nodes may have multiple parents.

Can anyone suggest a data structure (or better still a package!) for this structure.

We are expecting a lot of node so would like to able to retrieve a node and it's descendants as efficiently as possible.

Thanks,

Mick

29th May, 2018

phpMick started a new conversation Running Tests On Laradock. • 1 month ago

Hi,

Is anyone able to run tests on Laradock (using PhpStorm).

How do I install PHPUnit?

Thanks,

Mick

25th May, 2018

phpMick left a reply on New Deployment, Can't Login. • 1 month ago

Yes, we weren't using HTTPS. Sorted now.

24th May, 2018

phpMick started a new conversation New Deployment, Can't Login. • 1 month ago

Hi,

I swear that I have seen this before.

I have just deployed my application and migrated/seeded the db.

I can't login, I just get redirected back to login, without any errors.

Any ideas?

Mick

21st May, 2018

phpMick started a new conversation Laravel, Docker And Windows • 2 months ago

Hi,

Is anyone developing on Windows using Docker?

I'm just wondering you share your code between your host and container?

Mick

14th May, 2018

phpMick started a new conversation Mock An Object That Is Created By A Static Function. • 2 months ago

I am trying to unit test a function, in the middle of it is this line:

$authService = AadAuth::interactive();
static public function interactive()
    {
    //do some stuff       
        return $instance;
    }

AadAuth calls an external API, which I want to fake.

I don't see how this is possible.

Mick

phpMick started a new conversation Can't Work Out How To Mock This. • 2 months ago

Hi,

How can I mock this?:

$tenantid = $azure_api->ResourceManagement()->getSubscriptionTenantGuid(strtolower($request->guid));

This is what I have:

//mock the MAA
        $MAA = Mockery::mock('App\Connectors\MicrosoftAzureApi');

        //this needs a ResourceManagement
        $ResourceManagement = Mockery::mock('App\Connectors\MicrosoftAzureApi\ResourceManagement');
        //add the functions

        $ResourceManagement->shouldReceive('getSubscriptionTenantGuid')->once()->with($this->subscriptionID)->andReturn($this->tenantID);

//give it to the MAA
        $MAA->ResourceManagement =  $ResourceManagement;

When I try to use it, I get:

Method Mockery_0_App_Connectors_MicrosoftAzureApi::ResourceManagement() does not exist on this mock object

I'm not really sure what is happening here:

$tenantid = $azure_api->ResourceManagement()->getSubscriptionTenantGuid(strtolower($request->guid));

I don't really get how ResourceManagement is instantiated.

Thanks,

Mick

11th May, 2018

phpMick left a reply on Mocking External Actions • 2 months ago

Right, how about this:

public function a_master_admin_can_store()
    {


        $request = StoreSubscription::create('blah/blah  ', 'POST',[
            'guid' => $this->subscriptionID,
            'agreement_id' => $agreement->id
        ]);


        //mock the MAA
        $MAA = 
     Mockery::mock('App\Connectors\MicrosoftAzureApi');

        $controller = new AzureSubscriptionController();
        $response = $controller->store($request,$MAA);

    //assert something

    }

phpMick started a new conversation Mocking External Actions • 2 months ago

I have a controller function which instantiates a class which connects to Azure.

How do I test this using Mockery, so the connection to Azure is faked?

It's a bit like this:

 public function store(StoreSubscription $request)
    {

        $azure_api = new MicrosoftAzureApi();

        $tenantid = $azure_api->connectAndDoSomething();
   }

Thanks,

Mick

8th May, 2018

phpMick left a reply on Client Side Datatables • 2 months ago

Where you have this:

Route::resource('/calender', 'CalenderController');

Route::get('/calender/xaja', '[email protected]');

The Route::resource statement will catch the /calender/xaja route because it adds all these:


Verb        URI                     Action  Route Name
GET         /photos                 index   photos.index
GET         /photos/create          create  photos.create
POST        /photos                 store   photos.store
GET         /photos/{photo}         show    photos.show
GET         /photos/{photo}/edit    edit    photos.edit
PUT/PATCH   /photos/{photo}         update  photos.update
DELETE      /photos/{photo}         destroy photos.destroy

So, it looks like it will go to create on your calendar controller.

Does that help.

I would recommend that every developer uses Xdebug, it is tricky to set up but will allow you to set breakpoints and step through your code.

Mick

3rd May, 2018

phpMick left a reply on Client Side Datatables • 2 months ago

This: {message: "No query results for model [App\Calender] xaja",??

looks like it coming back from a query.

Are you sure your code is going where you think it is? Add some dd('test') statements.

"As I understand, the yajra package is created to handle server-side works of DataTables jQuery Plugin", but I want to use client-side.."

You are getting your data in your controller, just like you would with the package.

phpMick left a reply on Client Side Datatables • 2 months ago

Can you use your browsers debugging tools, to see what the actual AJAX response is? They must be different, in your two cases.

Have you looked at this?

https://github.com/yajra/laravel-datatables

Mick

17th April, 2018

phpMick left a reply on Store URL, Then Return Back After A Redirect. • 3 months ago

Yes, but sometimes, I want to go to the create group page, without redirecting to the previous.

In normal use, the show page comes after the create.

phpMick started a new conversation Store URL, Then Return Back After A Redirect. • 3 months ago

Hi,

Not sure how to describe this.

I want to store a place in a workflow, so that I can return back to it, after being directed somewhere else.

eg:

Adding a new user. 1, Choosing users group from a dropdown. 2, Pick the "add a new group option" - this then sends the user, to the new group page. 3, When new group is added, I want to go back to the page for adding a new user, so that they can choose the new group.

Should I just store the URL in session, then look for it, after adding the new group?

Just wondered if there was a clever way of doing this?

Thanks,

Mick

3rd April, 2018

phpMick started a new conversation Remove Empty Key From JSON. • 3 months ago

Does anyone have a clever way to do this?

I have some JSON (coming from https://github.com/lazychaser/laravel-nestedset), this is a small part of it:

1","description":"culpa","parent_name":null,"children":[]}]}]

I want to remove the children element when it is empty.

So, if it looks like this "children":[] remove it.

I could replace it with a space by using str_replace, I just wondered if there was anything better?

Thanks,

Mick

26th March, 2018

phpMick left a reply on Too Few Arguments To Function. • 3 months ago

Yes that got it, I tried use but missed the parenthesis.

Thanks.

phpMick started a new conversation Too Few Arguments To Function. • 3 months ago

Will someone please point out the problem with this code, I'm sure it's obvious but I can't see it. I thought this was how I was supposed to pass a parameter?

$allGroups = Cache::remember($keyName,1440 , function ($userGroupId) {

            return self::getGroupHierarchy($userGroupId);

        });

Type error: Too few arguments to function App\Models\UserGroup::App\Models\{closure}(), 0 passed in /home/vagrant/code/portal/vendor/laravel/framework/src/Illuminate/Cache/Repository.php on line 327 and exactly 1 expected (View: 

23rd March, 2018

phpMick started a new conversation How To Load/store Large Hierarchy. • 3 months ago

Hi,

Just wondered if anyone had any ideas about this, before I jump in.

1, I have a complicated hierarchy (user groups) which I need to build. This will be built by a recursive function which needs some logic which I cannot think of another way to achieve.

It needs to traverse down a tree (https://github.com/lazychaser/laravel-nestedset) but it needs to stop when it hits certain types of nodes.

I don't really want to do this with multiple SQL queries, so I am thinking of bringing back the tree, into a collection, then traversing through the collection somehow. This should be quicker because I won't be doing all the SQL queries.

Any thoughts on how to do this, has anyone done anything similar?

2, I then need to store this structure, so that I don't need to keep recreating it. I was originally thinking cache but as this structure is specific to the user, would it be better in the session?

Thanks,

Mick

22nd March, 2018

phpMick left a reply on Filled Form Not Validating • 3 months ago

As above.

I would rename the fields in the form, then they can go straight in the db.

Is this what everyone else does?

phpMick left a reply on Where To Put Redirect Login After Login. • 3 months ago

I was asking where to put the logic (for a conditional redirect), not where to change the redirect route.

The answer is add an authenticated method to the LoginController and put the logic in there.

phpMick left a reply on Testing Login Redirect. • 3 months ago

I had to do this to get that code working (L5.5):

$this->actingAs($user);

$test = $this->get(route('home'));

No, authenticated in LoginController still does not get called.

If I do this from the GUI, it works, this is only failing in test.

Mick

phpMick started a new conversation Testing Login Redirect. • 3 months ago

Hi,

I have some code with a redirect for some users on login: (https://laracasts.com/discuss/channels/general-discussion/where-to-put-redirect-login-after-login) .

I am now struggling to tests this, how can get this code to run in a test?

This is where I am:

 public function user_without_group_gets_message_page()
    {

        $user = create(User::class,['user_group_id' => null, 'role' => User::USER, 'password' => 'password']);

        //try posting to login

        $test = $this->post(route('login'),[
            'email' => $user->email,
            'password' => 'password'

        ]);

    }

Authenticated() in LoginController is not called. Any ideas why?

Mick

phpMick left a reply on Where To Put Redirect Login After Login. • 3 months ago

This is nothing to do with permissions.

This is how I solved it:

 protected function authenticated($request, $user)
    {
        if ( is_null($user->user_group_id )) {

            Auth::logout();

            session(['message' => 'blah blah blah]);

            return view('message-page');

        }else {
            return redirect('/home');
        }
    }

phpMick left a reply on Where To Put Redirect Login After Login. • 3 months ago

Thanks,

I just want to know the best place to put the login that will kick them out and redirect.

phpMick started a new conversation Where To Put Redirect Login After Login. • 3 months ago

If my user does not belong to any user groups, I want to kick them out with a redirect to a message page.

Where is the best place to put this logic?

Thanks,

Mick

20th March, 2018

phpMick left a reply on Function Name Must Be A String - View Composer • 4 months ago

Got it:

View::composer('partials.nav.right-menu-admin', function ($view) {
            $view->with('userGroups', UserGroup::all);
        });

Swapped $view()-> to be $view->.

Not sure where that came from?

Mick

phpMick started a new conversation Function Name Must Be A String - View Composer • 4 months ago

Hey,

What am I doing wrong here:

  View::composer('partials.nav.right-menu-admin', function ($view) {
            $view()->with('userGroups', UserGroup::all);
        });

Thanks,

Mick

phpMick started a new conversation Collection In Navbar. • 4 months ago

I need a collection (user groups) in my navbar on all pages.

Is this a job for a view composer?

Mick

14th March, 2018

phpMick left a reply on Forcing A Unique Rule To Ignore A Given ID In Form Request • 4 months ago

Yes, this is pretty much what I did, thanks guys.

phpMick left a reply on Validation • 4 months ago

Yes, I create a form request for each model and abstract the validation into that, just keeps my controllers neater.

13th March, 2018

phpMick left a reply on Forcing A Unique Rule To Ignore A Given ID In Form Request • 4 months ago

Yes, I use the same form request for both store new and update existing.

phpMick left a reply on Forcing A Unique Rule To Ignore A Given ID In Form Request • 4 months ago

The only problem is that it fails for creating new users.

Trying to get property of non-object

Because $user is not set.

I guess the only way round this is to check if there is a $user and choose to include the rule or not?

I don't think I had to this last time I did this?

phpMick left a reply on Forcing A Unique Rule To Ignore A Given ID In Form Request • 4 months ago

How do I use that in my array?:

return [
                'name'=>'required',
                'email'=>'required|email|unique:users,email'
}

I need to get this in somehow?:

Rule::unique('users')->ignore($user->id),

Mick

phpMick left a reply on Forcing A Unique Rule To Ignore A Given ID In Form Request • 4 months ago

Yes I am binding, yes that works!

phpMick left a reply on Forcing A Unique Rule To Ignore A Given ID In Form Request • 4 months ago

It's not the authenticated user I need, it is the one I am currently editing.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.