mikenewbuild

mikenewbuild

Owner at Newbuild Studio

Member Since 2 Years Ago

Manchester

Experience Points
67,260
Total
Experience

2,740 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
566
Lessons
Completed
Best Reply Awards
17
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 14
67,260 XP
Sep
14
2 months ago
Activity icon

Replied to Invalid Argument Supplied For Foreach() (View:

The it looks like your user doesn't have any remarks

Activity icon

Replied to Invalid Argument Supplied For Foreach() (View:

Also, it seems your logic requires a logged in user. Are you logged in when you view the page?

Activity icon

Replied to Invalid Argument Supplied For Foreach() (View:

@nakov beat me to it :)

I also think @jlrdw may be right and you are using ->first() incorrectly, because you're not calling it on date_seance ?

Activity icon

Replied to Invalid Argument Supplied For Foreach() (View:

Try adding ->get() to this line, so that you fetch some results. At the moment it's just an instance of the query builder.

$remarks = Remark::orderBy('instruction', 'asc')->where('instruction','like','%'.$request->input('search').'%')->get();
Activity icon

Replied to Package Job Splits Perfectly On Local But On Production, System Dispatches One Job And Then It Times Out

How frustrating. So your initial job is failing just because it times out? There's no exception being logged?

Is the data you are dealing with on production much larger?

If the job is trying to write to a file, then check that you have permission.

Are you trying to import data from an xls? Or export to an xls?

Activity icon

Replied to Package Job Splits Perfectly On Local But On Production, System Dispatches One Job And Then It Times Out

Are you sure that the queue is running on your production server?

Sep
09
3 months ago
Activity icon

Replied to Laravel

@rider I see. Is it possible to add your module_url value when you add the other data attributes to the notification?

Otherwise you could transform the $notifications and insert the extra value before you pass it to the view?

https://laravel.com/docs/6.0/collections#method-transform

Activity icon

Replied to Percentage Difference Between Dates

@inspiredprynce you're very welcome. Glad to hear it solved it for you.

If you don't need that level of accuracy (down to the second) you could probably solve it a little nicer:

$start = Carbon::parse("2018-05-06 13:50:20");
$end = Carbon::parse("2020-03-06 13:50:20");

$remaining = 100 * $end->diffInDays(now()) / $end->diffInDays($start); // 26.716417910448
Sep
06
3 months ago
Activity icon

Replied to Percentage Difference Between Dates

@snapey that was my assumption, but we know what assumptions make...

Activity icon

Replied to Percentage Difference Between Dates


$start = Carbon::parse("2018-05-06 13:50:20")->timestamp; // 1525614620

$end = Carbon::parse("2020-03-06 13:50:20")>timestamp; // 1583502620

$timespan = $end - $start; // 57888000

$current = Carbon::now()->timestamp - $start; // 42174783

$progress = $current / $timespan; // 0.72855830223881

$remaining = (1 - $progress) * 100; // 27.144169776119

Edit: added values as comments

Activity icon

Replied to Laravel

Hi @rider - have you looked at https://laravel.com/docs/5.7/eloquent-serialization#appending-values-to-json ?

Also, it's not great practise to access env() directly. It is better to access that value in a config file, one of the benefits being that the value gets cached.

Sep
05
3 months ago
Activity icon

Replied to Append

The 'page' key comes from the pagination if it's present ?page=2, etc.

Sep
04
3 months ago
Activity icon

Replied to Append

It appends all of the request keys (except 'page') to $products.

So the $products collection will contain key value pairs from the request as well as the original information.

Sep
03
3 months ago
Activity icon

Replied to Event Listeners + 8 Week Delayed Mail

I may be wrong but I think the 15 mins is the limit on the job's execution - so if it was going to take mare than 15mins to send the email, then you may have an issue. Setting a job to dispatch later (if I understand correctly) just means it won't get pulled off the queue until that point in time. In that sense, just adding the delay would achieve what you want.

That said, I think the benefits to the option @ftiersch suggests, means that it's potentially much easier to have visibility into upcoming notice emails, and also the ability to cancel (GDPR, etc.) or reschedule them if the need arises, as well as things like mark them sent, etc.

Activity icon

Replied to How To Append User's Name On Each Post Displayed When Post Model Only Have User_id

You can format your code with ```

Would this work?

$posts = Post::with('author')->whereIn('user_id', $userIds)->orWhere('user_id', $user->id)->orderBy('created_at', 'DESC')->get();

Assuming that matches your relationship, and that PostResource returns everything?

Activity icon

Replied to How To Avoid N+1 Problem When Loading More Results In Blade?

You don't need the repetition - in fact you're possibly overwriting the previous values.

Try:

$comments = Comment::with([
                    'children.children.children.children.children',
                    'owner',
                    'savedComments',
                    'votes'
                ])
                ->where('submission_id', $submission->id)
                ->whereNull('parent_id')
                ->orderBy('removed','asc')
                ->orderBy($sortBy, $direction)
                ->paginate(200);
Sep
01
3 months ago
Activity icon

Replied to How To Lock A Database Record Being Updated By A User In Laravel + Vue App

This will achieve it, the only risk is a race condition if the updates are sent at the same time.

I think it's better to check for equality on the timestamps as that prevents tampering with the fetched at field to force the update to be applied.

Activity icon

Replied to Where To Put Access Logic Vs Business Logic

No worries, good luck with it!

Aug
31
3 months ago
Activity icon

Replied to Authorization For Custom Guard?

Hey @ersanserkan - I think there's a couple of ways, and it depends what you want to achieve.

You can add the logic in the update method of the policy for that model, or if you want it to apply to all methods of that policy, you can use the before method in the policy.

If you want it to apply to all policies, then you should be able to apply it in the boot method of AuthServiceProvider.

Something like

public function boot()
{
    $this->registerPolicies();

    Gate::before(function($user) {
        return $user->is(auth('admin')->user());
    });
}

(not tested)

Activity icon

Replied to Authorization For Custom Guard?

Might help to provide an example of the type of guard you want to make?

Activity icon

Replied to How To Custom "With()" In Relationship Models ?

I think this

if(!isset($this->relations['teamleader_company_tags'])){
    $this->load('teamleader_company_tags');
}

could also be

$this->loadMissing('teamleader_company_tags');
Activity icon

Replied to Need Help To Understand How To Make A Relationship

I think you need to set up the inverse of your relationship.

class Events extends Model
{
    //

    public function event_type() {
        return $this->hasOne(EventType::class,'uid', 'type_uid');
    }
}

Assuming start_date is a column on eventi_calendario Then in the controller:

$events = Events::with('event_type')->whereBetween('start_date', [$date_start, $date_end])->get();

$eventsByType = $events->groupBy('event_type');

(not tested)

Activity icon

Replied to Where To Put Access Logic Vs Business Logic

@stephens coming with the hot tip! :)

Just having a look at this and in context with your other thread, @johncarter I think there's a couple of things to consider.

Is this a policy regarding a QuoteRequest or a Bid? I would say the latter, or more specifically a QuoteRequestBidPolicy if you're following the RESTful controller convention, and have a QuoteRequestBidController. Because if so, the guard is to prevent creating a new Bid that belongs to this QuoteRequest.

If you're wanting the ability when a user is viewing a quote request to either display an action to create a Bid, or supply a specific reason why they can't then using the ->status() (other thread) method to derive a component I still think is a good way to go.

This is, of course, subjective and is based on some assumptions - so please beware!

Aug
30
3 months ago
Activity icon

Replied to Que A Artisan Command

I just meant that, as you're not returning anything, then you will just see a blank screen.

For test purposes, try

Route::get('admin/backup', function() {
    App\Jobs\BackUp::dispatch();

    return "hi";
})->name('backup');

Then at least you'll know whether you're dispatching the job.

It sounds as if you are, so try checking the logs (storage/logs/) to see if the backup has thrown an error.

Activity icon

Replied to Where To Put Access Logic Vs Business Logic

I see. Then yes, that would be a cue for me to extract the "reason" logic on to the model, and access it in both the policy and view/controller/wherever as necessary.

Activity icon

Replied to Best Practice For $model->status Where Derived From Model Attributes

As this is presentational, I would handle the logic in the view layer, and have a component handle it.

Perhaps even something like @include('_partials.statuses.quote-requests.' $quoteRequest->status()) with a component for each value.

Activity icon

Replied to The Time Of Posting Is Not Correct In Laracasts Forum

Have noticed this too, and not sure if it's a TZ issue as I see an extra 5 hours added to post times when on an actual thread. However the times are correct on the /discuss page itself.

@JeffreyWay

Activity icon

Replied to Where To Put Access Logic Vs Business Logic

Hello - again this is subjective, but in my opinion I think this is the best use of a policy. You may be able to extract some of the query logic to scopes on the model, but policies are a good way of keeping this type of logic outside of controllers.

Activity icon

Replied to WARNING: A Post-install-cmd Script Terminated With An Error

What version of Laravel are you using? The optimize command was removed in 5.6 https://laravel-news.com/laravel-5-6-removes-artisan-optimize

Activity icon

Replied to Que A Artisan Command

What do you expect to appear? You're not returning anything from your route.

Activity icon

Replied to Best Practice For $model->status Where Derived From Model Attributes

IMHO this is the way to go. It's easy to reason about.

If deriving the status becomes expensive, then at that point you can explore caching strategies with better context rather than trying to optimise prematurely.

ps. I suspect that the order of your arguments should have hasBids() last, as the other two would never be reached?

Aug
26
3 months ago
Activity icon

Replied to "operator Not Supported For Strings" Error By Setting Up Mailable

Glad you solved it! :) I think the controller is possibly a better place to handle it too 👍

Activity icon

Replied to Duplicate Entry Issue With UpdateOrCreate

If you want to be able to update the slug/record the way I think you want to, you'll need to pass the original slug through with the form, and use that as the first argument.

Activity icon

Replied to Duplicate Entry Issue With UpdateOrCreate

The updateOrCreate method should take to arguments, the values you want to match on, and the values you want to update.

Currently I think your code is trying to look for a record with the slug and updated description, can't find a match and when it tries to create a record it violates the constraint.

Aug
25
3 months ago
Activity icon

Replied to How Many Controllers For The Same Thing?

They sound different enough to keep separate to me.

I think at first it seems like a good candidate to DRY up your code, but in my experience the differences are more likely to increase, and it becomes a pain point. I've often fallen into the trap of abstracting too early.

If you find the controllers sharing logic eg. filtering a query - then adding scopes to the model (or other shared methods) are a better opportunity in my experience.

Aug
23
3 months ago
Activity icon

Replied to "operator Not Supported For Strings" Error By Setting Up Mailable

Ah, I see. Okay, I think I know what's happening here. When you set the ->to property in the constructor, it is expecting an array (this property already exists in the Mailable class), but you are setting the email address as a string and later it tries to treat it as an array.

Try updating your code to this:

    public function __construct($data, $user)
    {
        $this->data = $data;
        $this->user = $user;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $fullname = $user->firstname.' '.$user->lastname;

        return $this->from($data['email'], $fullname)
                    ->to($user->email)    
                    ->subject($data['subject'])
                    ->message($data['bodymessage'])
                    ->markdown('emails.contact');
    }

Hopefully that should fix it for you.

It's a bit unusual that you are sending to the user's email, but using their name as the from name with a different email?

Activity icon

Replied to "operator Not Supported For Strings" Error By Setting Up Mailable

Yes, that's the model, which is correct.

Can you show the code where you call new ContactMail($data, $user) ? Presumably in a controller? Error could be there.

Activity icon

Replied to "operator Not Supported For Strings" Error By Setting Up Mailable

You should be passing in $user as a model, not a collection.

Activity icon

Replied to How To Send Slack Notification When A Exception Is Thrown.

I can only guess, because I'm not sure why you would see the routes file as output, but I suspect you have a syntax error elsewhere in your code.

Activity icon

Replied to How To Send Slack Notification When A Exception Is Thrown.

Looks like Log::error($exception->getMessage()) in Handler.php is missing a semicolon at the end.

Aug
22
3 months ago
Activity icon

Replied to API For Games

Super!

Activity icon

Replied to API For Games

Are you using the web routes? Sounds like you may be better using api routes if I have understood what you're trying to achieve correctly.

Aug
16
3 months ago
Activity icon

Replied to Clean Code

Without using any other techniques, you can extract the logic that you repeat, and store the variances in an array.

$paths = ['file_path1','file_path2','file_path3'];

foreach ($paths as $path) {
    if ($request->hasfile($path)) { 
        $project->{$path} = $request->{$path}->store(); 
    }
}
Aug
08
4 months ago
Activity icon

Replied to Integrate Different Sources Of Notifications

Well, working back from that integrations would need to return a collection of instances with notify methods that accept a payload, and already have enough details do their thing.

So first of all I would try to figure out if / how to aggregate all those integration types and have them conform to that contract.

It sounds like maybe all of these integration types are too distinct to be solved simply by a polymorphic relationship. But it could be solved by polymorphism in the stricter sense, whereby you have factory methods to return the correct model instances, that way the data you store for each can be independent so your Stream model would have direct relationships to webhook_integrations, email_integrations etc. and integrations is a convenient aggregator for them.

Again, wildly hypothetical!

Activity icon

Replied to How To Output A Json Array And Loop Through Variables

👍

You don't need to do any json conversion when you'r in blade/PHP land. You constructed a nested array in your Controller, and passed it down to the blade file, where you can iterate over it.

The fact that you later convert it to json for the response is because that's a format that javascript and other languages can parse.

Activity icon

Replied to How To Output A Json Array And Loop Through Variables

Okay so get rid of the json_encode stuff and do:

@foreach ($guests as $guest)
{{ $guest['guest_name'] }} | {{ $guest['gluten'] }}
@endforeach
Activity icon

Replied to How To Output A Json Array And Loop Through Variables

Maybe also try $item['guest_name'] rather than $item->guest_name if this is an array you've built up yourself, rather than an array of objects.

Activity icon

Replied to How To Output A Json Array And Loop Through Variables

Somewhere you're calling NewGalaTransaction(..., $guests, ...) are you passing an array or json at that point? Can you show that code?

Activity icon

Replied to How To Output A Json Array And Loop Through Variables

So is $guests already json encoded? Do you need to do:

$array = json_decode($guests);

If possible, passing a php array in initially would be more typical.

Activity icon

Replied to Hello Friends | Users Table Field Keeps Return True

@cronix quite. I know it shouldn't really matter in this case, but type is one of those keywords I avoid.

@respect - did you try casting that field to an integer as previously suggested?