shadrix

shadrix

Member Since 1 Year Ago

Experience Points 43,340
Experience
Level
Lessons Completed 389
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.

15 Jan
2 days ago

shadrix left a reply on When To Use Something Like Aws S3?

@ohffs Thanks! Good to know! Btw what about https://www.fastly.com? I found this also interesting and it's up to 50$ for free.

shadrix started a new conversation When To Use Something Like Aws S3?

I finished my project and I'm currently going into the production phase. It's my first big project and I'm trying to learn everything about improving the performance of a webpage. However, it overwhelms me quite a bit... (not really noob friendly)

So when and why would you use services like aws s3?

If you google for that, there obviously pages that make some couple of bucks with it for promoting it. So I cannot really trust their pros&cons.

To explain my project:

A user can sell offers and each offer contains at least one image. I'm going to use DigitalOcean (DO) as a Server. Currently, I think I would save the images with DO Spaces. (it should be the same to s3).

But I'm not quite sure, why you guys are using aws s3 but are using DO as the server.

Thanks!

14 Jan
3 days ago

shadrix left a reply on How To Reduce App.js?

@wilk_randall Ah you are right! I only used mix(['vue'])....

Now with this change it looks like this:

/js/app.js    1.01 MB      33  [emitted]  [big]  /js/app
js/vendor.js    3.75 MB      34  [emitted]  [big]  js/vendor
/js/moment.js  193 bytes      35  [emitted]         /js/moment
/js/canvas.js     1.4 kB      36  [emitted]         /js/canvas
js/manifest.js    2.23 kB      37  [emitted]         js/manifest
/css/app.css     289 kB      33  [emitted]  [big]  /js/app

Thanks for the tip, I'llDo you have any other tips?

shadrix left a reply on How To Reduce App.js?

@wilk_randall I hope you are not a bot :P if you look to the code above you might see /vendor.js and manifest.js. That is why I'm already doing :)

shadrix started a new conversation How To Reduce App.js?

I would love to know your tips on reducing app.js

My current problem is that in development my app.js is about 9mb big. When minified it is still about 3.68mb big.

/js/app.js    3.68 MB      33  [emitted]  [big]  /js/app
/js/moment.js     982 kB      34  [emitted]  [big]  /js/moment
/js/vendor.js    92.2 kB      35  [emitted]         /js/vendor
/js/canvas.js     1.4 kB      36  [emitted]         /js/canvas
/js/manifest.js    2.23 kB      37  [emitted]         /js/manifest
/css/app.css     289 kB      33  [emitted]  [big]  /js/app

I have two ideas how to reduce the .js

  • I could have two .js one for guests and a second for an authenticated user that is loaded additionally -or I could split this for every single page (but I fear this is more of a hassle...

Chrome's audit says that just for "Script Evaluation" it takes 12,237 ms....

Thank you for your tips!

11 Dec
1 month ago

shadrix left a reply on Cannot Log In - Session Not Working In Artisan Serve But In Valet It Does

Maybe for feature readers, I could not fix it, but I made valet share much faster.

First of all I created a free account on ngrok and then with `~/.composer/vendor/laravel/valet/bin/ngrok authtoken <YOUR_AUTHTOKEN>``

You can add your auth token.

So after that you need to specificy your region. Since I'm from Europe it made it super fast.

just write: valet share -region=eu

shadrix left a reply on Cannot Log In - Session Not Working In Artisan Serve But In Valet It Does

@SNAPEY - @snapey you are right but as written above I'm using it to view it on my phone. Since Valet Share goes through ngrok.io it's way slower, because of the "middleman". If I use artisan serveand go through the local network it's super fast.

10 Dec
1 month ago

shadrix started a new conversation Cannot Log In - Session Not Working In Artisan Serve But In Valet It Does

Hey, I don't know why but my session is not working while using php artisan serve --host 0.0.0.0

First I had to remove \App\Http\Middleware\VerifyCsrfToken::class,, but now while debugging on my phone I want to log in and it won't work.

I think my SESSION_DOMAIN is wrong, but I cannot figure it out.

With Laravel Valet my .env looks like this:

APP_URL=http://myproject.test
SESSION_DOMAIN=.myproject.test #using it for subdomains

Now with php artisan serve it's

APP_URL=http://192.168.1.34:8000
SESSION_DOMAIN=192.168.1.34

But I had to remove VerifyCsrfToken because for some reason I get TokenMismatchException.

I don't want to use Laravel Valet Serve because it is so slow...

Any idea why my session is not working?

03 Dec
1 month ago

shadrix started a new conversation Question Towards Access Control List (ACL). Should Be A "normal" User Be A Role?

I'm currently learning about ACL but I'm not quite sure how I should implement it.

My current user migration table looks like this:

Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name')->unique()->nullable();
        $table->string('email')->unique()->nullable();
        $table->string('password')->nullable();
        $table->string('avatar')->nullable();
        $table->boolean('seller')->default(false);
        $table->boolean('confirmed')->default(false);
        ...
});

Now my thought was to remove the last two booleans in favor of the role ACL table.

Some questions I have:

Would you create a role with the name "buyer"? That is the normal user on my platform, where confirmed is set to true and the seller is set to false.

What about "unconfirmed" users? Those who did not confirm the confirmation mail yet? Would you create a role for them as well?

Another question is that how would you define the user factory?

Normally, I would just write:

factory->define(App\User::class, function (Faker $faker) {
   static $password;
  return [
    'name' => $faker->unique()->userName,
    'email' => $faker->unique()->safeEmail,
    'password' => $password?: $password = 'secret',
    'avatar' => $faker->imageUrl(220, 220, 'people'),
    'confirmed' => true,
    'cook' => true,
    ....
 ]
});

How would you attach it when the syntax would be $user->givePermissionTo('create offers');?

Thank you!

######(p.S. sorry about all the questions, normally I would have created more discussions...)

01 Dec
1 month ago

shadrix left a reply on Using Laravel Packages In Nova

The short answer is no.

Normal Laravel Packages need to ship with Laravel Nova Packages so you can use it both (for example with the Laravel Ban package).

You can have a look at https://novapackages.com what packages there are.

30 Nov
1 month ago

shadrix left a reply on Nova Column Not Found - Do I Need ID In My Model?

@sepiksu @realrandyallen it's really hard to choose the best answer here.

I tried the first option from @realrandyallen and added the applyOrderings() method as in the issue described. However, as soon I tried to edit values I run into other issues.

So @sepiksu gets the best answer because I'm going to add the id.

shadrix left a reply on Nova Column Not Found - Do I Need ID In My Model?

@SEPIKSU - @realrandyallen yes you are right! A pity this is not a default option.

shadrix started a new conversation Nova Column Not Found - Do I Need ID In My Model?

So my simple model is not using ID as a column. However, with Nova, it shows me the error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'unsplash.id' in 'order clause' (SQL: select * fromunsplashorder byunsplash.iddesc limit 26 offset 0)"

My resource looks like this.

` public static $model = 'App\Unsplash';

public static $title = 'city';

public static $search = [
    'city'
];

public function fields(Request $request)
{
    return [
       Text::make('City'),
       Text::make('PhotoId'),
    ];
}`

What to do?

27 Nov
1 month ago

shadrix left a reply on How And Where To Store A Secured API Key (for Example For Algolia)?

@d9705996 Because restricted API keys can be easily attacked if you know how. I just quote from here:

The referrer is an HTTP header that is sent by browsers. Like all HTTP headers, it can be spoofed, so you should not rely on it to secure your data.

So that is why you should do backend and combine it with restricted api.

26 Nov
1 month ago

shadrix left a reply on How And Where To Store A Secured API Key (for Example For Algolia)?

@d9705996 Finally we are getting closer. There are two ways how to secure the api keys. You can combine them. As you have read it's:

-restricted API Keys
-secured API Keys

However, I'm interested in secured API Keys. I want to use my backend to generate the save keys.

After the backend generates the key, I want them to be echoed out in the header.

Like:

<script>
    window.App = {!! json_encode([
       'topSecretKey' => mymagicmethod('algolia')
    ]) !!};
    </script>

shadrix left a reply on How And Where To Store A Secured API Key (for Example For Algolia)?

@d9705996 I really appreciate your help, but I'm a bit confused right now. I'm trying to explain it a bit more what I'm doing.

I implemented Algolia Places with Vue, so I actually cannot use Laravel Scout, since I don't need my backend for this.

At this part in the documentation, Algolia writes that we should secure the api keys.

So that is why I'm here, because I'm not quite sure if the session id is enough and where to put the code.

The goal is just to read the key dynamically out

shadrix left a reply on How And Where To Store A Secured API Key (for Example For Algolia)?

@D9705996 - Sorry, the part of session()->getId() is obvious, but thank you. How ever, where would you save the part of code? still in config/services.php?

shadrix started a new conversation How And Where To Store A Secured API Key (for Example For Algolia)?

So I'm trying to implement this:

//example from the page
$currentUserID = 1; // Replace by the current user ID

$securedApiKey = \AlgoliaSearch\Client::generateSecuredApiKey(
  'YourSearchOnlyApiKey', // Make sure to use a search key
  [
    'filters' => 'viewable_by:'.$currentUserID
  ]
);

However, since the user is not always logged in I don't have a user id. So my guess is just to take the session id, it should work the same right?

But now I'm curious, where should I put this part of code?

My first thought was in config.services. But can it work even though I cache the config?

Should I put it somewhere else?

To fetch the key for the frontend, I'm saving it to window.App.keys

16 Nov
2 months ago

shadrix left a reply on Naming Question: What Is The Appropriate Short Name For BillingSeller?

@aurawindsurfing and @martinbean, sorry for the miscommunication... ?

So I try to explain it. In Order.php I have the relationships seller() and buyer() (or @martinbean's naming scheme is also nice)

However, for each Order, I'm saving the Seller Address + Name data and the Buyer Address + Name data.

I'm using a polymorphic table called addresses to save all kinds of addresses.

To save the addresses of the orders I have two extra models OrderBillingSeller and OrderBillingBuyer. That is important for morphing the right type.

Currently, I'm using the naming scheme:

//in Order.php
public function *****(can't find a good name)()
{
    return $this->hasOne('App\OrderBillingSeller');
}

public function billing()
{
    return $this->hasOne('App\OrderBillingBuyer');
}

I'm not really happy about it, but I associate billing as the invoice/billing for the buyer and for the seller I'm not sure what to use.

Btw thank you for your help nonetheless!

13 Nov
2 months 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 months 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
2 months 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
2 months 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
2 months 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
2 months 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
3 months 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
3 months 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
3 months 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
4 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
4 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
4 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
4 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
4 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
4 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
5 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()