shadrix

shadrix

Member Since 11 Months Ago

Experience Points 40,890
Experience
Level
Lessons Completed 369
Lessons
Completed
Best Reply Awards 0
Best Answer
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.

13 Nov
1 day ago

shadrix started a new conversation Naming Question: What Is The Appropriate Short Name For BillingSeller?

Currently, in my Order Table, I've got the relationships billingSeller and billingBuyer.

I would like to change it so that billing is always the buyer data and **** for the seller.

I have no idea how I could name it, do you have any idea?

Thank you!

shadrix left a reply on Relationship HasOne Over Two Tables

@Cronix I know, sorry about that! It was hard for me to decide (not really is it the best answer as I wrote, but I wanted to give it to him so he is more motivated to help others)

12 Nov
2 days ago

shadrix left a reply on Relationship HasOne Over Two Tables

@mekaeil I'm not really happy about that, but I'm going to do it. Thank you for your help

shadrix left a reply on Relationship HasOne Over Two Tables

@CRONIX - I had this before, but I liked the idea of having user_addresses and that's it.

So before that, I had, offer_addresses, billing_addresses, user_addresses, seller_addresses.

shadrix left a reply on Relationship HasOne Over Two Tables

@STAUDENMEIR - I thought the same but how should belongsToMany set the attributes like is_physical, is_billing, is_offer etc?

shadrix left a reply on Relationship HasOne Over Two Tables

@mekaeil because I have sooo many tables that need addresses, like order (billing), offer(pickup address), order(seller_address), user (physical address) etc. I cannot just create a simple users_address table. My tables look similar to this one:

asdf source

shadrix started a new conversation Relationship HasOne Over Two Tables

I'm not sure how to solve this problem:

picture

I have an address table and a user_addresses table.

My goal is to get a relationship like:

public function address() { return $this->hasOne(UserAddress::class) ->where('is_physical', true); }

However, I want to get with $user->address not the UserAddress table but the Address table. And my goal is to write: $user->address()->create(['street_number' => '25c']) so I'm creating the Address table but at the same time I'm creating the UserAddress table and set the `is_physical´to true.

Is this somehow possible?

p.S. sorry about the title, I just don't know how to simplify my problem in a title...

09 Nov
5 days ago

shadrix left a reply on How To Handle A Dummy User To Replace A User?

@martinbean Oh, I forgot about default models! That is cool!

But why would you only soft-delete the record? Why not completely?

shadrix left a reply on How To Handle A Dummy User To Replace A User?

Good morning, thanks for your reply.

The conversations were private between the users? No need to redact one half of the conversation?

Yes, they are private. But since GDPR hit us I'm trying to delete everything that I don't need anymore.

I would leave the record alone, just overwrite the previous user's name with something like 'anon' and make up new values for the other fields.

I think I'm going to do it so. Thanks!

08 Nov
6 days ago

shadrix started a new conversation How To Handle A Dummy User To Replace A User?

I'm not sure how to handle this the correct way.

Let us say we have messages table with dozens of messages from a user in a conversation.

Now, the user decides to leave the website and delete his account. My "goal" is to completely delete the user from the user table (no soft-deleting) and update all relationships in all the tables I have. Especially, the messages table worries me, because it can be quite long.

How would you do this? Do you have one dummy user in the usertable and just update all foreign keys to the dummy user?

24 Oct
3 weeks ago

shadrix left a reply on Why Is There A <br> When Using Markdown In Email?

Ok, I see now. The difference in render is:

with

Thanks,
my App

and without

Thanks,

my App

Sorry for the question, but at first it showed me everything correctly

shadrix started a new conversation Why Is There A <br> When Using Markdown In Email?

Sorry for the question,

but I wonder. Why is there a in the markdown examples?

Like in https://laravel.com/docs/5.6/mail#markdown-mailables (scroll a bit down)

Example:

Thanks,<br>
{{ config('app.name') }}
@endcomponent

I thought markdown would always single line break after breaking one row.

21 Oct
3 weeks ago

shadrix left a reply on Very Slow PHPUnit Tests Using PHP7.2 Or PHP7.1.

Wtf I'm working on my project for several months, and everything was fine. I have 411 assertions, that normally takes about 30secs. Now it's 7.43 Minutes WTF. I don't know what suddenly happened.

17 Oct
4 weeks ago

shadrix started a new conversation Is It Possible To Render $slots Into Html?

I need your help. Is it possible to render this.$slots.defaultinto HTML?

It should be so simple, but cannot find it anywhere.

I tried it with but it didn't work

let modalDiv = document.createElement('div')

    let slotComponent = Vue.extend(this.$slots.default)

    return new slotComponent().$mount(modalDiv).$el
11 Oct
1 month ago

shadrix started a new conversation Is There Something Wrong When Adding Properties To Window?

That question bothered me quite a while.

Is there something wrong when I use:

  window.app = new Vue({ ... all my components}) ?

I feel like I'm adding a lot to window just that I can use it everywhere easily.

Is there a consequence to it or doesn't it matter?

04 Oct
1 month ago

shadrix left a reply on What Are Your Thoughts On Soft Deleting?

@oscarteg that's a really good tip, didn't know about it!

@rwashingtonTA It was my same thought but wasn't sure. Know I have to check how I can merge it with the GDPR law...

shadrix started a new conversation What Are Your Thoughts On Soft Deleting?

I'm curious what you are thinking about soft deleting?

Where are you using it?

Let's say we have a Forum Thread with Comments and Likes.

The owner of the thread decides to delete the thread. Are you going to hard or soft deleting the thread plus the comments and likes?

I'm not sure how to handle it, because "what if" I need that information of the thread or the comments. (I had one case 10 years ago, where the police asked for a dataset of a user).

14 Sep
2 months ago

shadrix left a reply on How To Implement A Multi Rating System?

@MikeRees Okay interesting! Thank you! Learned a lot :)

shadrix left a reply on How To Implement A Multi Rating System?

@MikeRees I need your help again... Hopefully, you are reading this again.

enter image description here

I changed the diagram a bit so that I can add the review bodies.

I implemented it like this, but then it struck me. Why do I need the pivot table, when I could use table "ratings" as my pivot table?

Because let's say I have the id of an "offer review", I can get easily all collections of ratings. And I get all values at the same time.

So I think I could just delete "offer_review_rating_types" or do I miss something?

13 Sep
2 months ago

shadrix left a reply on How To Implement A Multi Rating System?

@MikeRees OH I see! I will give it a try!

And here is what I use to add a picture:

[![enter image description here][1]][1]
[1]: https://i.imgur.com/Rr9g0BY.png

How did you draw the diagram? Reminds me of a program that I used at school but it was years ago...

shadrix left a reply on How To Implement A Multi Rating System?

@MikeRees thank you for your help. It's hard to for me to understand it still. I tried to "translate" your tips into this diagram, but I think it's weird for me.

enter image description here

so you would add all different kinds of ratings in one table? still confused sorry

shadrix started a new conversation How To Implement A Multi Rating System?

First of all. Thank you for your time and help. I feel bad asking questions, but I'm stuck.

Currently, I'm trying to implement a rating system. Not a normal one. It's very similar to the Airbnb one, where a User can give the overall rating from 1-5 but also has the option to rate other things like the location/value etc.

In my case, I have an "offer" table. Each offer can be a different type of thing. It can be food, it can be an event, a service etc.

Every offer can be ordered by a user.

Now after buying the offer you can rate it. However, for each type of offer, you have optional ratings.

For example for the type "food", you can optionally rate the taste, the freshness, the quantity or the value.

I'm not sure how to implement this... my current thought is like this:

List item

Every review consists of the public body text, the optional private text to the seller and the response of the seller (if there is one). And it's overall rating.

One review has one optional review. In the example of food, I would save the additional ratings in JSON.

But again in my last post, you cannot calculate the averages etc very well with it. But I don't want to add for every offer type a special table again.

How would you handle this?

shadrix left a reply on Is There A Right Approach To Calculate The Average Of A Rating System?

Guys it's super hard for me to mark the right answer. Every response was helpful. But I feel bad if I don't mark anything. I choose the one was the lowest XP and because I really like the approach with redis.

Thank you for the help!

12 Sep
2 months ago

shadrix started a new conversation Is There A Right Approach To Calculate The Average Of A Rating System?

I'm curious what your thoughts are about this.

Let's say I have an offering table (for some items) with a rating system from 1-5. How would you implement it when you would like to display the average rating of an offer? I see two possible ways:

I could add those two columns in the offer table:

rate_count : 0,
rate_average: 0

And for each new review in the rating table, I would recalculate the rate_count and rate_average.

The second possibility is that I'm calculating the average on the fly with the aggregate methods avg() and count().

Personally, I feel like it's not a good idea to calculate these numbers in every query. However, in one episode Jeff is explaining how to implement a "favorite/liking" system. In there he counts the sum of likes with

 return $this->favorites->count();

How would you handle this?

07 Sep
2 months ago

shadrix started a new conversation Is There A Free Https Tunneling?

I just implemented Stripe's Payment Request Button. It needs to have https to be shown. I'm using valet share but that needs to be http.

Is there a free https tunneling?

24 Aug
2 months ago

shadrix left a reply on Mocking Stripe - How Not To Call The API

@Drfraker thank you! Helped me a lot. Btw you should have named yourself "DrFaker" :P You know how to mock ;)

20 Aug
2 months ago

shadrix started a new conversation Mocking Stripe - How Not To Call The API

I feel bad asking, but I don't know how to solve my test. I need to test if a user is being charged or not. In my unit test, I'm testing my method with the real API. But in my feature test, I don't want to use the real API again.

I have a job "ProcessPayment" and somewhere in the handle method I'm calling $this->chargeBuyer();

 protected function chargeBuyer()
 {
    $customer = $this->firstOrCreateCustomer(); //it finds the Stripe\Customer

    return $this->order
                ->buyer
                ->payment()
                ->chargeOrder($this->order, $customer); //this part should be mocked (I know it works).
 }

How do I do this? My first approach is (it's not working but just an idea)

 /** @test */
 public function it_charges_user() 
 {
    $this->orderMock = \Mockery::mock(Order::class);

$this->orderMock->shouldReceive('accepted')
               ->once()
               ->andReturn(true);

    $this->orderMock->shouldReceive('buyer->customerId')
               ->once()
               ->andReturn(true);

    $this->orderMock->shouldReceive('transaction->source_id')
               ->once()
               ->andReturn('jibberish');

    $this->orderMock->shouldReceive('buyer->customer->create')
               ->once()
               ->with(['source' => 'jibberish'])
               ->andReturn('some-customer');

    $this->orderMock->shouldReceive('buyer->payment->chargeOrder')
               ->once()
               ->with('order', 'customer')
               ->andReturn('charged');

    $payment = new ProcessPayment($this->orderMock); //Inject Order

    $payment->handle(); //Start my Job
}

You see that this is super gross, but I don't know how to handle the test...

Here is an excerpt of the job code:

class ProcessPayment implements ShouldQueue
{
   use ...;

 public $order;

/**
 * Create a new job instance.
 *
 * @return void
 */
public function __construct(Order $order)
{
    $this->order = $order;
}

/**
 * Execute the job.
 *
 * @return void
 */
public function handle()
{
    if(! $this->order->accepted) return;

    if(! $this->order->transaction->isChargable){

        return $this->notifyBuyerToPay();
    }
    
    $this->chargeBuyer();
    
    //save charge_id in transactions


    //set payment job to the time to payout
    //
    //order complete?

}

 /**
 * Checks if Buyer is customer and 
 * is charge for the Order. 
 * @return Stripe\Charge 
 */
protected function chargeBuyer()
{
    $customer = $this->findOrCreateCustomer();

    return $this->order
                ->buyer
                ->payment()
                ->chargeOrder($this->order, $customer);
}
14 Aug
3 months ago

shadrix started a new conversation Hiding The Public Email Through A Middle Email. How Would You Call It?

I'm looking for a way that hides the user's email through a middle email. Airbnb uses it for communication purposes after booking, for example. [email protected] But it's obviously not the real mail.

Is there a package out there that does that? I don't know how you would call such a thing.

shadrix left a reply on Paged Resource Collection Not Working

@sgtpepper THANK YOU. I was looking for answers but could not find it. Indeed you cannot use response()->json()

13 Aug
3 months ago

shadrix started a new conversation Question To API Resource Collection - How To Use Own Names

So I'm learning about API Resource and I need this for using HashIds.

I'm a bit confused how I can use my "own" names in a collection.

In single models I can say:

public function toArray($request)
{
    return [
        'myownid' => $this->id,
        'username' => $this->name,
        'awesomeemail' => $this->email,
    ];
}

In collection I need to write:

public function toArray($request)
{
    return [
        'data' => $this->collection,
    ];
}

But how can I change the attribute names?

So I can use: 'myownid' => Hashids::encode($this->id),

My collection result is quite big:

$order->with(['items', 'items.offer', 'items.offer.offering', 'transaction', 'billing', 'billing.buyer', 'seller'])
              ->filter($filters) //query filter
              ->paginate(10)
10 Aug
3 months ago

shadrix left a reply on Mockery - How To Mock A Class? (Somehow It Still Fires The "real" Methods)

@martinbean Ok I see, that sucks. I hoped it would work without injecting it our retrieving from a container... Thank you anyways!

shadrix started a new conversation Mockery - How To Mock A Class? (Somehow It Still Fires The "real" Methods)

I feel bad asking, but I'm a bit confused with mockery. Sometimes it works perfectly but right now, I cannot get it to work.

It should not be that hard, my code is quite simple:

    $payment = new Payment(auth()->user());

    $payment->updateOrCreateCustomer($this->data['source']['source']['id']);

In a Unit Test I'm already testing Payment, so I don't need this code above to work.

In the FeatureTest in Setup:

public function setUp()
{
    parent::setUp();
    
    $this->mock = \Mockery::mock(Payment::class);

    app()->instance(Payment::class, $this->mock); 

    $this->mock->shouldReceive('updateOrCreateCustomer')
               ->once()
               ->andReturn('value'); //I don't care for the value
 }
18 Jul
3 months ago

shadrix left a reply on Laravel Mix: Prevent Moment.js Locales

@steveperrito thanks but don't forget to

const webpack = require('webpack');

13 Jul
4 months ago

shadrix left a reply on Can You Register A Helper Method In A Package Globally So It's Not Being Refreshed?

So I found another way for my problem, an maybe it helps.

ServiceProvider:

    $this->app->singleton('myclass', function ($app) {
        return new Myclass($app);
    });

And in the helpers

   return app()->make(Tongue::class);

shadrix started a new conversation Can You Register A Helper Method In A Package Globally So It's Not Being Refreshed?

So in my own vendor package, I have a helper method that returns me the Class that I'm using:

 function myclass()
 {
     return app(Myclass::class);
 }

With that, I can use it as a global method myclass() in my project.

Now, I'm a bit stuck, because it does not remember (obviously) it's current state and forgets it's protected values. How would you handle it?

Just that you understand where I have these problems:

For example in my main Project RouteServiceProvider.

 Myclass::detect(); //sets protected value
 Myclass::current(); //gets the protected value
 myclass()->detect(); //sets protected value
 myclass()->current(); //forgets it -> null because it calles a new instance

Thank you!

12 Jul
4 months ago

shadrix left a reply on Is There A Good Package For Subdomain Laravel Translations?

@lostdreamer_nl many thanks! It works :) still, need to adjust my needs to it.

And just one little side question, if you have a static page like about us. How would you save the other language, in /lang/de/de.json?

shadrix left a reply on Is There A Good Package For Subdomain Laravel Translations?

@lostdreamer_nl ha sorry I think I was not clear enough, but its really nice thanks!

So what you showed me is how I can translate models. But first I need a good way to route and redirect to the languages etc.

shadrix started a new conversation Is There A Good Package For Subdomain Laravel Translations?

I need your help. I'm a bit overwhelmed with localization.

My goals are to have subdomains referencing the current language used. So de.myapp.com for German, fr.myapp.com for French but myapp.com for English.

I thought it would be easy but I just find unmaintained packages. The only one I really like is made by mcamara. But still not perfect but it just adds prefixes like myapp.com/en. (And even if you change it you can't use the middleware because it just adds the prefix...)

Do you have some tips for me? Thank you!

11 Jul
4 months ago

shadrix left a reply on How To Boot A Model Via Trait? Event "updated" Is Not Called

@lostdreamer_nl thank you it works :) it's super weird that it needs to be there, because in other traits it worked just fine. Thank you for your help! And good to know with protected

10 Jul
4 months ago

shadrix left a reply on How To Boot A Model Via Trait? Event "updated" Is Not Called

@click

I recreated my problem and loaded to github. You just need to go to the unit test to test it. No installation at all. I stripped everything out what is not important.

https://github.com/pmochine/TraitBootBug

shadrix left a reply on How To Boot A Model Via Trait? Event "updated" Is Not Called

@lostdreamer_nl sorry forgot to write it. That is the weird part. In phpunit auth()->check() is true. In the model event its also true, but in trait it is never been called...

shadrix started a new conversation How To Boot A Model Via Trait? Event "updated" Is Not Called

In my phpunit test I'm updating values:

/** @test */
public function it_updates_newsletter_when_user_privacy_is_updated() 
{
    
    $privacy = create('App\UserPrivacy', ['user_id' => auth()->id()]);

    $privacy->update(['firstname' => 'Philipp']);

}

And I'm trying to catch the updated event in a trait. But the thing is, it is never beeing called. Here is the trait:

trait UpdatesNewsletter
{
    /**
     * Boot the trait.
     */
    protected static function bootUpdatesNewsletter()
    {
        if (auth()->guest()) return;

        static::updated(function ($model){
            var_dump('is called by trait');
        });
        
    }
}

Just for my sanity check, I wrote the event catch for the model itself.

class UserPrivacy extends Model
{
    use UpdatesNewsletter;

     /**
      * Boot the model.
      */
    protected static function boot()
    {
        parent::boot();

        static::updated(function ($privacy){
            var_dump('is called by class');
        });
    }
}

And in my console I see the only message:

string(18) "is called by class"

What am I doing wrong?

09 Jul
4 months ago

shadrix left a reply on How To Use Mockery For A Class Used In A Controller?

@Talinon thanks! It helps me a lot. Mockery is super weird to understand, especially because I didn't need it until now. Thank you again!

shadrix left a reply on How To Use Mockery For A Class Used In A Controller?

Ah I see I need to use something like that

 $this->mock = \Mockery::mock(Newsletter::class);

 $this->app->instance(Newsletter::class, $this->mock);

I'm getting on a right track.

shadrix started a new conversation How To Use Mockery For A Class Used In A Controller?

Let's say my controller looks like that.

public function store()
{
    Newsletter::subscribePending($email);
}

And Newsletter is a Class to use MailChimps Api easier.

Now how do I write a test for it?

I tried this, but it does not work. (I'm new to Mockery and it sends the data to mailchimp).

class NewsletterTest extends TestCase {

    use RefreshDatabase;

    public function setUp()
    {
        parent::setUp();

        \Mockery::mock(Newsletter::class);
    }

    public function tearDown() {
        \Mockery::close();
    }


    /** @test */
    public function a_guest_can_subscribe_to_newsletter() 
    {
        $this->withoutExceptionHandling();
        $this->json('post', route('newsletter.store'), ['email' => '[email protected]'])
             ->assertStatus(201);
    }
}

shadrix started a new conversation Would You Save Newsletters Emails On DB Or Leave It On MailChimp?

So I'm new to Newsletters and I'm following a tutorial on how to set up a newsletter system with MailChimp in Laravel.

The question that arises is if I need to store the given email on my database as well?

Just in case if I want to dismiss the services of MailChimp. What are you doing?