phpMick

Member Since 5 Years Ago

Experience Points
60,150
Total
Experience

4,850 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
148
Lessons
Completed
Best Reply Awards
34
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 13
60,150 XP
Jan
13
4 days ago
Activity icon

Replied to Collection With Created_at From Pivot Table.

Thanks, I used a resource in the end.

Activity icon

Replied to Collection With Created_at From Pivot Table.

Yeah, sorry. I updated my last post.

Activity icon

Replied to Collection With Created_at From Pivot Table.

Hurrah (post updated)!

The timestamps are not include because they are not in my $fillable array!

If I remove the $fillable array they appear.

Now, how do I get the invited.created_at to be on the same level as the user fields?

Activity icon

Replied to Collection With Created_at From Pivot Table.

I have the relationship like this:

return $this->belongsToMany(User::class)->as('invited')->withTimestamps();

So I can see the intermediate model in the Collection, the question is how to get it in the JSON.

Activity icon

Started a new Conversation Collection With Created_at From Pivot Table.

Hi,

I have tables users and groups and therefore group_user.

group_user has timestamps and they are included in the group->users relationship

Now I want the created_at to be included in the JSON response when requesting the users which belong to a group.

So I have a function which basically does this:

return $group->users;

So, the JSON should look like this:

[{,"first":"Stephanie","last":"Roberts","mobile":"+123456","email":"[email protected]", "created_at":"*****"}]

The created_at should be when the pivot record was created, not the user record.

I will also rename the created_at field.

Jan
08
1 week ago
Activity icon

Replied to Full Text Search.

Cheers, I already did that.

Activity icon

Replied to Full Text Search.

Hi @michaloravec,

No. I didn't use your code. I don't like pasting code I don't understand.

Can you explain why this doesn't work?

SELECT * FROM
    thingies WHERE
    MATCH (title) AGAINST ('*sing' IN BOOLEAN MODE);

Cheers,

Mick

Activity icon

Replied to Full Text Search.

So it looks like LIKE is better than MATCH because I can search for %sin% ?

Activity icon

Replied to Full Text Search.

Then why doesn't this work:

select * from
              thingies where
      MATCH (title) AGAINST ('usin') 

but this does:

select * from
              thingies where
      MATCH (title) AGAINST ('using') 

Activity icon

Replied to Full Text Search.

Is MATCH better than LIKE?

How can I use a wildcard with MATCH?

eg Searching for the word testing, I want to be able to use the search term esti

the same as this:

select * from thingy WHERE title LIKE '%earc%';
Activity icon

Replied to Full Text Search.

Yeah, so just use a MATCH, I will give that a go. Cheers.

Activity icon

Started a new Conversation Full Text Search.

I have a field which I need to do a text search on (MySQL).

What is the current thinking on how should i do this? Probably looking for a simple solution, this may be the only time it is used in this API.

Cheers,

Mick

Jan
06
1 week ago
Activity icon

Replied to Help Upgrading To L8.

Yeah, read that and updated my composer.json before running the update.

My problem is that I don't understand the debug from the update.

Activity icon

Started a new Conversation Help Upgrading To L8.

Can someone help me troubleshoot my upgrade:

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install laravel/framework v8.21.0
    - Conclusion: don't install laravel/framework v8.20.1

etc

    - Installation request for dyrynda/laravel-efficient-uuid 4.3.0 -> satisfiable by dyrynda/laravel-efficient-uuid[4.3.0].
    - Conclusion: don't install laravel/framework v8.0.1

etc

 laravel/passport 9.x-dev requires illuminate/support ^6.18.31|^7.22.4 -> satisfiable by laravel/framework[v7.29.3, 7.x-dev, 6.x-dev], illuminate/supp

I don't really understand what the problem is?

What do I need to learn to master this?

Cheers,

Mick

Jan
04
1 week ago
Activity icon

Started a new Conversation Can I Validate Request Headers In My Rules Array?

Can I validate request headers in my rules array?

I want to check that this is a valid ip:

$request->header('x-forwarded-for');
Dec
14
1 month ago
Activity icon

Started a new Conversation Count For Each Created_at Day?

Hi,

I am trying to group by the created_at date and get a count of the records(events) for each day.

I currently have this but it's not quite there:

$page->events
            ->whereBetween('created_at', [$this->from, $this->to])
            ->get()
            ->groupBy(function($date) {
                return Carbon::parse($date->created_at)->format('Y-m-d'); // grouping by years
            });

Cheers,

Mick

Dec
04
1 month ago
Activity icon

Started a new Conversation Select Group By And Count.

How can I write this using Eloquent?:

select p.name,  c.title, count(e.id) as clicks from posts p
    inner join comments c on p.id = c.comment_id
    inner join events e on e.comment_id = c.id
    group by c.title;

I'm trying to get this:

post name, comment title, clicks

Cheers,

Mick

Dec
02
1 month ago
Activity icon

Replied to Optional Foreign Key Or Pivot Table?

I do have two tables: 1, pages 2, links (with a page_id)

but sometimes I get links which do not belong to pages.

Activity icon

Started a new Conversation Optional Foreign Key Or Pivot Table?

Hi,

I'm not sure if I have something wrong here.

Tables: pages, links

The links table has a page_id foreign key (I need a way to get all the links for a page, these links do belong to the page).

Sometimes links are created which do not belong to page. What do I do then?

Allow a null foreign key or should I have a table which joins pages to links.

Mick

Dec
01
1 month ago
Activity icon

Replied to Select All Anchor Tags In HTML String.

Just got this working, seems pretty easy. Any reason to use anything else?

$dom = new DOMDocument;
$dom->loadHTML($content);
$links = $dom->getElementsByTagName('a');
foreach($links as $link){
    $href = $link->getAttribute('href');
    $link->setAttribute('href','test.com');
}
$string =  $dom->saveHTML();
      	

Mick

Activity icon

Replied to Select All Anchor Tags In HTML String.

I'm not getting images, I am getting links.

I am going to replace them with links to my server, so that I can track clicks and redirect.

Nov
30
1 month ago
Activity icon

Started a new Conversation Select All Anchor Tags In HTML String.

Hi,

What is the best way to do this? I want to replace the with links which I can track.

I'm currently thinking something like this:

        $dom = new DOMDocument;
        $dom->loadHTML($content);
        $imgs = $dom->getElementsByTagName('a');

Mick

Nov
27
1 month ago
Activity icon

Replied to Insert Html Element In Html String.

Good question!

Yeah, that's pretty neat.

Activity icon

Started a new Conversation Insert Html Element In Html String.

This is another question related to pixel tracking.

If I have a HTML string, what is the easiest way to insert a tag, before the closing body?

Mick

Activity icon

Started a new Conversation Implementing Tracking Pixels.

I'm trying to add "tracking pixels" to some HTML snippets which are saved in my db.

Do I just need to add an image tag that makes a call to my server?

Like this?

<img src="trackinghook.php?id=123456">

Then I can log when the HTML was served?

Is there any need for an actual pixel?

Cheers,

Mick

Nov
26
1 month ago
Activity icon

Started a new Conversation Better Way To Reload Model To Get The Id?

Hi,

I'm doing this:

$page = make(Page::class);

$response = $this->postJson(route('pages.store'), $page->toArray());
$reload = $page::where('title','=',$page->title)->first();

$this->assertDatabaseHas('other_table',['thingable_id' => $reload->id]);

So I make the model, then post i to the store, where it is created. I then need the id for the assert.

I tried fresh and refresh but they don't work.

Cheers,

Mick

Activity icon

Replied to Build Up Eloquent Query Using Options.

Yeah, that's what I was looking for. Cheers.

Activity icon

Started a new Conversation Build Up Eloquent Query Using Options.

What's a better way to do this:

if(isset($this->status)){
            $collection = Page::whereBetween('created_at',[$this->from, $this->to])->where('status','',)->orderBy('created_at', 'desc')->paginate();
 } else {
            $collection = Page::whereBetween('created_at',[$this->from, $this->to])->orderBy('created_at', 'desc')- 
 >paginate();
 }

The from and to dates are also optional, so I want a solution where I can use them if present.

Mick

Nov
25
1 month ago
Activity icon

Started a new Conversation Specifying Date Range For Index Page Of API.

Hi,

My API index page needs from and to parameters.

What is the best way to do this and what date format should I pass (selecting against created_at).

I have started using a GET with URL parameters (because nothing changes on the server) but this doesn't feel right.

Mick

Activity icon

Started a new Conversation Model Factories Confusion

What am I doing wrong here?

I want all the Things to have the same campaign_id which I am passing in, they don't.

test:

$campaign = create(Campaign::class);

 $pages = factory(Thing::class, 5)->create([
          'campaign_id' => $campaign->id,
  ]);

ThingFactory

$factory->define(Thing::class, function (Faker $faker) {
    return  [
         'campaign_id' => factory(Campaign::class)->create()->id,
         'title' => $faker->sentence(6),
    ];
});

A new Campaign is created for each Thing. I thought that this just worked?

Mick

Nov
23
1 month ago
Activity icon

Started a new Conversation S3 Testing: This Driver Does Not Support Creating Temporary URLs

Hi,

Trying to write a test for uploading files to s3 (using Spatie laravel-medialibrary).

When I do this:

$media->getTemporaryUrl(60)

I get : This driver does not support creating temporary URLs

Is there anyway round this, I am faking s3 in my test:

Storage::fake('s3');

Mick

Nov
10
2 months ago
Activity icon

Replied to Add To Name When Sending Mail.

This the best way?:

$recipients = $contacts->map(function ($item, $key) {
            return ['name' => "{$item->name_first} {$item->name_last}",
            'email' => $item->email];
        });
Activity icon

Replied to Add To Name When Sending Mail.

Good question @snapey !

It's an Eloquent Collection, do I need to make that an array with name and email?

contact_identifier = "b0003570-37e0-3d59-b844-262e57a37a4d"
name_first = "Theresa"
name_last = "Bailey"
mobile = "+447837242536"
email = "[email protected]"
Activity icon

Started a new Conversation Add To Name When Sending Mail.

Hi,

I am sending mail like this:

Mail::to($contacts)->send(new ThingMail());

When I look at the mail, it only has an address in the To field. How do I add the names?

Cheers,

Mick

Nov
04
2 months ago
Activity icon

Started a new Conversation SES Add Custom Headers.

Hi,

I'm trying to add some custom headers to an email, which I am sending using SES.

I have this working with Sendgrid:

https://sendgrid.com/docs/API_Reference/SMTP_API/unique_arguments.html

but not sure about SES.

Any ideas?

Mick

Oct
20
2 months ago
Activity icon

Replied to Email Tracking Package.

Thanks, I'm going to get something simple working and see how it goes.

Activity icon

Replied to Email Tracking Package.

Thanks @martinbean. Yes, this was my initial thought.

The problem is that we don't want to be tied to a provider.

:-(

Activity icon

Replied to Email Tracking Package.

That's great @bugsysha, thanks. Yes I think this is the way I am headed.

Can you provide any more detail on how you did the tracking pixel? Does it just contain a link which goes to a webhook , with an id?

Cheers,

Mick

Activity icon

Started a new Conversation Email Tracking Package.

Hi,

Is anyone using an e-mail tracking package which they would recommend?

or

Has anyone done this from scratch? I want to track opening, bouncing and link clicking?

Cheers,

Mick

Oct
15
3 months ago
Activity icon

Replied to Collection Of Related Models.

Yeah so this:

$users = User::whereHas('tokens', function($query) {
    $query->whereJsonContains('scopes','manage');
})->get();

is exactly what I wanted. I think it looks much neater?

Are we agreed that @michaloravec gets the best answer?

Thank's for your help everyone, much appreciated.

Activity icon

Replied to Collection Of Related Models.

I was simplifying things (well trying to). This is the actual code:

$userIds = PassportToken::whereJsonContains('scopes','manage')->get()->pluck('user_id')->toArray();
$users = User::whereIn('id',$userIds)->get();

So It is a bit like this:

token 1  ------ > manage scope ------ > user 1
token 2  ------ > manage scope  ------ >user 2
token 3  ------ >  manage scope ------ >user 3
token 4  ------ > other scope ------ >user 1
token 5  ------ > manage scope, other scope ------ >user 4

I want to get all of the users, with the manage scope.

Activity icon

Replied to Collection Of Related Models.

@tykus are you sure about this: "each Token instance in the collection will have its own users attribute"

$token->user currently returns the user Model.

What I want, is to somehow do $tokens->users

Activity icon

Replied to Collection Of Related Models.

Sorry, that was wrong, I have now updated my original post.

A token is assigned to a user. It's one to many.

Does it read OK now?

Activity icon

Started a new Conversation Collection Of Related Models.

I have struggled with this a few time and am sure there must be a Laravel way of doing this.

I have a collection of tokens which are assigned to a user. The tokens table has a user_id in it and $token->user gives me a User model (there is a belongsTo relationship).

I now want to get a collection of all the users, how should I do this? I currently pluck all the user_ids to an array like this:

$userIds = $tokens->pluck('user_id')->toArray();
$users = User::whereIn('id',$userIds)->get();

Surely there is a better way?

Oct
14
3 months ago
Activity icon

Replied to Passport - Get All Users With Scope.

This is working but horrific:

$userIds = \App\Models\PassportToken::whereJsonContains('scopes','manage')->get()->pluck('user_id')->toArray();

$users = User::whereIn('id',$userIds)->get();

Activity icon

Replied to Passport - Get All Users With Scope.

This is working to get the tokens:

$tokens = \App\Models\PassportToken::whereJsonContains('scopes','manage')->get();

And I can get $token->user

Anything better?

What I would really like is a collection of users.

Mick

Activity icon

Replied to Testing Scopes.

Awesome, that is just what I was looking for. Thanks, I stopped reading when I got to the JS section!

Oct
13
3 months ago
Activity icon

Started a new Conversation Passport - Get All Users With Scope.

So I'm trying to get a list of users which have been granted access to a scope.

I can see that PassportToken::all() will return all the rows from oauth_access_tokens and I can see the scopes and users in there.

id = "68a0f65ce1b28030279b3ec488bc4b8b04a179985fca892401bae8ea44d"
user_id = {int} 179
client_id = "914673d3-99ea-4fd9-88a2-02ac02b62dd9"
name = null
scopes = "["manage"]"
revoked = {int} 0

I just wondered if there was an easy way to get them?

Mick

Activity icon

Replied to Testing Scopes.

I mean just adding a scope to a group of routes:

->middleware(['scope:manage'])

I just want to check that my token request for a scope is working, then ensure that the route only works if the token has the scope.

This is how I get my token:


        $postArray = [
            'grant_type' => 'password',
            'client_id' => \env('CLIENT_ID'),
            'client_secret' => \env('CLIENT_SECRET'),
            'username' => $user->username,
            'password' => $password,
            'scope' => 'manage'
        ];

        $response = $this->postJson(\route('passport.token'), $postArray);

Maybe I'm just trying to test the framework and I should forget about it.

Mick

Oct
12
3 months ago
Activity icon

Started a new Conversation Testing Scopes.

Hi,

I'm just adding some scopes for my api. I have a test that requests a token for a scope.

Is there anyway I can check that this token is for the scope?

Currently thinking I just need to try and use it against a scoped route.