mstrauss

mstrauss

Web Developer at Freelance/Remote

Member Since 4 Years Ago

Experience Points
58,200
Total
Experience

1,800 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
230
Lessons
Completed
Best Reply Awards
56
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.

Level 12
58,200 XP
Jan
18
5 months ago
Activity icon

Replied to Adding Props On Component Won't Pass It Down

@dingo_d

Not 100% sure as I have been working with a different Javascript library recently and am a bit rusty on Vue, but does the below work for the class?

<button class="'btn btn-'" :class="button_class" @click="submit">{{button_title}}
Activity icon

Replied to Recursive Select Option Dropdownlist

@noblemfd

I think you would need to do something like this since it is loaded via this relation $managers = Staff::all();

               @if($managers->managers->count() > 0 )
                 @foreach($managers->mangers as $manager)
                   <option value="{{$manager->id}}">{{$manager->fullName}}</option>
                 @endforeach
               @endif
          </select>

To make it more readable, you may want to just load the managers directly like: $managers = Manger::all(), then it should work as you originally expected.

Activity icon

Awarded Best Reply on How Can I Set The Default Value Laravel <select> Element?

@oxbir

Since the Product can have many Categories per your relationship and the pivot table implication, you would have to use an in_array method (or something similar) like:

            @foreach($categories as $category)
                <option value="{{ $category->id }}" {{ (in_array($category->id, $product->categories->pluck('id')->toArray()) ? 'selected' : '' }}>{{ $category->name }}</option>
            @endforeach

Does each Product possibly belong to many different Categories? Or does each Product belong to one Category? Because if the later is true, then you would have to adjust your relationship to a oneToMany as opposed to the current manyToMany with the pivot table.

Activity icon

Replied to How Can I Set The Default Value Laravel <select> Element?

@oxbir

Since the Product can have many Categories per your relationship and the pivot table implication, you would have to use an in_array method (or something similar) like:

            @foreach($categories as $category)
                <option value="{{ $category->id }}" {{ (in_array($category->id, $product->categories->pluck('id')->toArray()) ? 'selected' : '' }}>{{ $category->name }}</option>
            @endforeach

Does each Product possibly belong to many different Categories? Or does each Product belong to one Category? Because if the later is true, then you would have to adjust your relationship to a oneToMany as opposed to the current manyToMany with the pivot table.

Jan
16
5 months ago
Activity icon

Replied to Hashing And Storing Large Data In MySQL Database,

@gouseferoz

You said:

I am trying to hash my data before saving it to the database mainly to: 1) Save the size of the data being saved - If you are going to save large lines of data 2) Security.

Only point two (2) really makes sense. As @tray2 said, encrypting is not a space saving mechanism, it is for security purposes only. If you are trying to be storage-conscious, which is always a good idea, maybe you can only encrypt the sensitive data, as opposed to encrypting the whole DB. To do so, consider using an Encyptable Trait. It's not too difficult to set up on your own but if you prefer a package, here is one that looks pretty straightforward:

https://github.com/gregoryduckworth/Encryptable

Jan
09
6 months ago
Activity icon

Replied to Passing Hidden Field Value Back To Livewire Component Is Null

Sorry, I missed that line in your original reply.

Did you include the below@livewireAssets in the head of your base layout template?

<head>
 // other stuff... 


    @livewireAssets
</head>
Activity icon

Replied to Passing Hidden Field Value Back To Livewire Component Is Null

@wallyj

Did you also change the property on your class?

public $deal_id;

to

public $dealId;
Activity icon

Awarded Best Reply on Data Is Not Deleted ?

@neeraj1005

You may have to tweak this a bit, but something like:

                      <td>

<form action="{{ route('avatars.destroy', $data->id) }}" method="POST">
    @method('DELETE')
    @csrf

                        <button type='submit' class="btn btn-primary btn-block"><b>Delete</b></a>

</form>
                      </td>


Activity icon

Replied to Data Is Not Deleted ?

@neeraj1005

You may have to tweak this a bit, but something like:

                      <td>

<form action="{{ route('avatars.destroy', $data->id) }}" method="POST">
    @method('DELETE')
    @csrf

                        <button type='submit' class="btn btn-primary btn-block"><b>Delete</b></a>

</form>
                      </td>


Activity icon

Replied to Data Is Not Deleted ?

@neeraj1005

You usually have to use a form (or an AJAX request) with a spoofed Delete method as opposed to an anchor tag, because the anchor will use a Get method.

The Route Resource expects the following per the docs:

Verb    Path    Action  Route Name
GET /photo  index   avatar.index
GET /photo/create   create  avatar.create
POST    /photo  store   avatar.store
GET /photo/{photo}  show    avatar.show
GET /photo/{photo}/edit edit    avatar.edit
PUT/PATCH   /photo/{photo}  update  avatar.update
**DELETE    /photo/{photo}  destroy avatar.destroy**
Activity icon

Replied to Passing Hidden Field Value Back To Livewire Component Is Null

@wallyj

Oh, sorry about that. I see what you're saying. Perhaps it has something to do with the snake_case? In the examples I have seen, and it my own Livewire test apps, I have always used camelCase

Activity icon

Replied to Passing Hidden Field Value Back To Livewire Component Is Null

@wallyj

In the hidden field, it appears you are using the incorrect variable name:

<input type="hidden" name="deal_id" id="deal_id" value="{{ $deal['id'] }}" wire:model="dealid">

Try changing it to:

<input type="hidden" name="deal_id" id="deal_id" value="{{ $deal['id'] }}" wire:model="deal_id">
Activity icon

Replied to Model Static Events On Boot Slow Together When Update Slug

@kris99

Does the updated, below, work by itself?

        static::updated(function ($model) {

            $model->generateSlug();

        });

I would think it would cause an endless loop because it would, of course, be called when a model is updated. But then, in the generateSlug method, when you call $this->save() the static::updated method would be called again, leading to an infinite loop.

Activity icon

Replied to Laravel 5.0 To 5.5 Upgrade, Session Flash Messages Not Working

I may have been barking up the wrong tree in my prior answer. I'm actually thinking it's an issue with how you are sharing the view, i.e. below in your Base controller:

if (Session::has('flash_warning')) {
        View::share('flash_warning', Session::get('flash_warning'));
    }

Try this instead (from the docs):

Occasionally, you may need to share a piece of data with all views that are rendered by your application. You may do so using the view facade's share method. Typically, you should place calls to share within a service provider's boot method. You are free to add them to the AppServiceProvider or generate a separate service provider to house them:

<?php

namespace App\Providers;

use Illuminate\Support\Facades\View;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        View::share('key', 'value');
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
Activity icon

Replied to Laravel 5.0 To 5.5 Upgrade, Session Flash Messages Not Working

@lauriek

The docs from 5.0 state the below (which is what you have)

Sometimes you may wish to store items in the session only for the next request. You may do so using the Session::flash method:

Session::flash('key', 'value');

But the 5.5 docs display it slightly differently, see below:

Sometimes you may wish to store items in the session only for the next request. You may do so using the flash method. Data stored in the session using this method will only be available during the subsequent HTTP request, and then will be deleted. Flash data is primarily useful for short-lived status messages:

$request->session()->flash('status', 'Task was successful!');

While they appear to be equivalent, just using a helper versus a Facade, try replacing your flash message creation in the controller with the above ^^^

Activity icon

Replied to WhereIn In Query Doesn't Work For Array, Any Solution?

Hi @manjumjn

A couple of things I noticed. First, I don't see any return statements. Second, shouldn't the fallback value of your null coalescing operator be false as opposed to null? Or, just use the PHPissetfunction as, per the docs it will:

isset — Determine if a variable is declared and is different than NULL

I actually haven't seen null coalescing operator used in conjunction with the when clause before. Traditionally, you see a more direct comparison like below:

$query->when($filters['subjects'] === true, function ($query) {
    return $query->...
});

Below is my suggestion:

public function scopeFilter($query, array $filters)
    {
        $query->when(isset($filters['subjects']), function ($query, $data) {
            //Subjects ids will be comma seperated string eg : 127,125
            $subject_array = explode(',', htmlspecialchars_decode($data));
            return $query->where(function ($query) use ($subject_array) {
                $query->whereIn('subjects_ids', $subject_array);
            });
        })->when(isset($filters['topics']), function ($query, $data) {
            //topics ids will be comma seperated string eg : 127,125
            $topic_array = explode(',', htmlspecialchars_decode($data));
            return $query->where(function ($query) use ($topic_array) {
                $query->whereIn('topics_ids', $topic_array);
            });
        })->when(isset($filters['search']), function ($query, $search) {
            return $query->where(function ($query) use ($search) {
                $query->where('name', 'like', '%'.$search.'%');
            });
        });

    }
Activity icon

Awarded Best Reply on Laravel Policies

@glenuk

Ah, I see what you are saying. Per the docs

As previously discussed, some actions like create may not require a model instance. In these situations, you should pass a class name to the authorize method. The class name will be used to determine which policy to use when authorizing the action:

Try the below:

public function export(Request $request)
{

    // pass class name
    $this->authorize('export', PurchaseOrder::class);

    $data = $request->validate([
       'dateFrom' => 'required|date',
       'dateTo' => 'required|date',
        'statuses' => 'required|array',
    ]);

    return (new PurchaseOrdersExport($request->dateFrom, $request->dateTo, $request->statuses))->download('PurchaseOrders.'.$request->file_format);
}

Activity icon

Replied to Laravel Policies

@glenuk

Ah, I see what you are saying. Per the docs

As previously discussed, some actions like create may not require a model instance. In these situations, you should pass a class name to the authorize method. The class name will be used to determine which policy to use when authorizing the action:

Try the below:

public function export(Request $request)
{

    // pass class name
    $this->authorize('export', PurchaseOrder::class);

    $data = $request->validate([
       'dateFrom' => 'required|date',
       'dateTo' => 'required|date',
        'statuses' => 'required|array',
    ]);

    return (new PurchaseOrdersExport($request->dateFrom, $request->dateTo, $request->statuses))->download('PurchaseOrders.'.$request->file_format);
}

Activity icon

Replied to Laravel FirstOrCreate With Multiple Attributes

@phoenix5

@tykus answer above is right. So in your case, you would include all necessary items to check for the existence of the the models in the first argument and then, if a model cannot be found with those details, a new model will be created with them. So something like the below:

$log_pn = Log_panne::firstOrCreate(['n_s' => $request->get('n_serie'),'panne_id' => $panne_id]);

And then you wouldn't really need the balance of the below code as the model would already be saved to the DB with the items:

// don't need... 
$log_pn->n_s = $request->get('n_serie');
$log_pn->panne_id = $panne_id;
$log_pn->save();
Jan
08
6 months ago
Activity icon

Replied to Laravel Policies

Hi @glenuk

I'm with @kevinbui on this. Double check the Array Intersect function info from the PHP manual, below:

array_intersect() returns an array containing all the values of array1 that are present in all the arguments.

Because you are passing an empty array as the second parameter, array_intersect will always return an empty array, whose count will always be zero (0).

Activity icon

Replied to Get Lastest Rows Of Duplicates

@drissboumlik

Sorry, I should be testing these things but I have been quite but lately. The above code is calling the only method on a "non-collection". Try this instead:

App\Stat::all()->only('Id_Externe', 'Date_Heure_Note')->duplicates('Date_Heure_Note');
Jan
05
6 months ago
Activity icon

Replied to Get Lastest Rows Of Duplicates

@drissboumlik

Yep, I should have probably used only not get. See below. That doesn't quite explain the error you're getting, but it may resolve it.

App\Stat::only('Id_Externe', 'Date_Heure_Note')->duplicates('Date_Heure_Note');
Activity icon

Replied to Group Collection Info

Oh, sorry, perhaps it's weekOfYear and not just week. Also no need for the method parentheses (). Check out the docs: https://carbon.nesbot.com/docs/#api-getters


$groupedCollection = $payed->only('quantity', 'DueDate', 'TotalValue')->groupBy(function ($item){
    return Carbon::parse($item->DueDate)->weekOfYear;
});
Activity icon

Replied to Group Collection Info

How about something like the below? Just a heads up, this will not take into account the Year of the DueDate but per your requested format above, that doesn't seem to matter.



$groupedCollection = $payed->only('quantity', 'DueDate', 'TotalValue')->groupBy(function ($item){
    return Carbon::parse($item->DueDate)->week();
});
Activity icon

Replied to Group Collection Info

@conixs

What were the results when you tried the above groupBy collection method? And don't forget that the groupBy collection method, like most other collection methods, does not affect the original collection, so you have to assign it to a new var, like below:

$groupedCollection = $payed->groupBy(function ($item){
    return Carbon::parse($item->DueDate)->format('Y-m');
});
Activity icon

Replied to How To Solve This Error; Invalid Argument Supplied For For Each()

@icelander

My guess is that it is this line:

@foreach($order->cart->items as $item)

I didn't see $items assigned in the controller method. Try the below instead:

@foreach($order->cart as $item)
Activity icon

Awarded Best Reply on Laravel Blade Directives Auth

I like @emadiga solution. But I think it would be an or statement as opposed to an &&

@if(Auth::guard('web')->check() || Auth::guard('student')->check())
// Your logic here
@endif