RoboRobok

RoboRobok

Member Since 3 Years Ago

Experience Points 23,120
Experience Level 5

1,880 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 16
Lessons
Completed
Best Reply Awards 26
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.

10 Jul
1 month ago

RoboRobok started a new conversation How To Run My Own PHP Script On Homestead Provision?

I made a script generating Homestead.yaml based on my projects folder tree. What it does is basically mapping folder name to its *.test domain, using either /public folder (if it exists) or folder root. It works great, coupled with dnsmasq I no longer need to register any projects in hosts nor Homestead.yaml manually.

The next step would be to run this script automatically during Homestead's provision. Is that possible? Or maybe it's even possible to do it in more fancy way? I'd like to just make sure all my folders work with their domain and Homestead config, because of certificates, doesn't support any wildcard syntax.

04 Jul
1 month ago

RoboRobok left a reply on How To Implement Remember Me Functionality By Laravel Passport?

Dont get too crazy with these security topics. Implicit grants are insecure. Local storage is insecure. Life is insecure.

RoboRobok left a reply on How To Implement Remember Me Functionality By Laravel Passport?

I wouldnt use an app where I need to log in every single time.

RoboRobok left a reply on Best Place In Project To Define Query Scope If There Is No Model?

If you want to put it inside a controller, I'm assuming there is only one page using it. You can just place this login inside your controller action if it's not useful anywhere else.

RoboRobok left a reply on How To Implement Remember Me Functionality By Laravel Passport?

@bobbybouwmann what do you mean by session? PHP session or session storage? Because PHP session is just data linked to a cookie, nothing more.

For remember me to work, Id say the best place to keep the token in is local storage. Cookies are by design not the best to work with APIs, as they are automatically sent by the browser no matter what.

RoboRobok left a reply on Hash Validation And Password Problem

Why wouldn't you add a custom validation rule?

RoboRobok left a reply on How Often Would I Refresh The Offline Access Token In A Web App?

However every time you request a new access_token using the refresh_token you also get a new refresh_token, so this should cover that.

This is actually not true. The only time you get a new refresh token is when you exchange the authorization code, which was obtained by accepting a consent screen with offline access being explicitly requested. You cannot get a new refresh token without user interaction, at least with Google API, but I believe thats part of OAuth 2.0 protocol. Refresh tokens are too sensitive and giving them out with every new access token request would have been a security trap.

03 Jul
1 month ago

RoboRobok left a reply on How Html Developer Can Work With Live Site?

So what if the basics didn't change? It has nothing to do with anything really. Some quirky logic behind your thinking pattern here.

RoboRobok left a reply on How Html Developer Can Work With Live Site?

You argue here like it was your first week of programming.

RoboRobok left a reply on Paginate BelongsToMany Relationship Records If More Than Set Limit

You almost made it:

$posts = $category->posts()->paginate(20);

Any Query Builder in Laravel has access to paginate() method and relationship called as a method behaves like a Query Builder.

Relationship called as a property is Eloquent Collection, which doesn't have paginate() method.

RoboRobok left a reply on Get Distinct Eloquent Relation Data Count And Records In Laravel

All is correct, I'm only not sure about the 3rd point:

3rd : we slice the array from index 0 to the random number generate and so we get a unique length for the array for each post category.

Not sure what you mean by unique length. What this line does, is just cutting the array to make it of random length between 1 and n, where n in your case is 27.

Let's consider this example of 5 instead of 27, for simplicity:

$categoryIds = range(1, 5);
// [1, 2, 3, 4, 5]

shuffle($categoryIds);
// let's say it's now [3, 1, 4, 5, 2]

$categoryIds = array_slice($categoryIds, rand(0, count($categoryIds) - 1));
// this line will do anything between array_slice($categoryIds, 0) and array_slice($categoryIds, 4), which means:
// array_slice($categoryIds, 0) => [3, 1, 4, 5, 2]
// array_slice($categoryIds, 1) => [1, 4, 5, 2]
// array_slice($categoryIds, 2) => [4, 5, 2]
// array_slice($categoryIds, 3) => [5, 2]
// array_slice($categoryIds, 4) => [2]

I hope it's crystal clear now :)

RoboRobok left a reply on Get Distinct Eloquent Relation Data Count And Records In Laravel

The fact that you limited your random entries to 3 doesn't mean it will never duplicate. Please use the code I posted above.

Using composite primary keys is a great idea. It uses an array:

$table->primary(['category_id', 'post_id']);

Remember about setting up foreign keys as well.

RoboRobok left a reply on How Html Developer Can Work With Live Site?

The problem is that you will go nowhere with the basics of programming today, as far as web development is considered. This is because of the background.

It's just like building a house. Was it easier or harder to build a house 5000 years ago? You can say it was harder, because there were less materials available. And you are right - if was more difficult to build a house 5000 years ago. But it's only true for a house standard of 5000 years ago.

Same goes with websites. You can build a simple, static page today and it will be easier than it used to be. But your website will be nowhere near expectations of web user in 2019. And I believe this is how it should be put.

RoboRobok left a reply on Get Distinct Eloquent Relation Data Count And Records In Laravel

If you want to generate random unique numbers, you can do it like this:

$categoryIds = range(1, 27);

shuffle($categoryIds);

$categoryIds = array_slice($categoryIds, rand(0, count($categoryIds) - 1));

RoboRobok left a reply on Get Distinct Eloquent Relation Data Count And Records In Laravel

I see. To be honest, this is where I'd make an assumption that these pairs are unique and improve my faker to follow that rule. Placing a UNIQUE index is a great idea too.

Remember that sometimes it's good to have assumptions about your code/data quality instead of trying to make your code adaptable to all circumstances. You will thank me later :)

RoboRobok left a reply on Forbidden Access For Portion Of My App From Phone + Tablet

Can you start from justifying why? Why would you restrict access on mobile/tablet?

Also, what is that part of the app that you want to hide? Is it just an element or entire route?

RoboRobok left a reply on Get Distinct Eloquent Relation Data Count And Records In Laravel

What do you mean by distinct? You have duplicates in your pivot table? Is there a reason for that? If not, I would clean the database and put a UNIQUE index of this pair in the pivot.

RoboRobok left a reply on How Html Developer Can Work With Live Site?

@jlrdw when have you started web development? I started 17 years ago. And I can assure you this is much difficult today and each year it gets more and more difficult.

You know what? There are tons of books on quantum mechanics, yet only few people are experts. Since when the availability of tutorials make the subject easy? You need to intellectually digest the subject anyway and web development A.D. 2019 is tons and tons of knowledge, relations between topics and many nuances. Unless you mean "how difficult it is to be a noob".

It's the market demand and technology complexity that change the scope of web development, not the availability of tutorials, LOL.

RoboRobok left a reply on How Html Developer Can Work With Live Site?

@SERGIU17 - I'm not saying it's not hard, but web development is harder today. If HTML and CSS are the only skills, it's only suitable for very small projects.

RoboRobok left a reply on How Html Developer Can Work With Live Site?

What answer do you expect? Knowing HTML and CSS is like no skill these days. How would he work on Vue project? He wouldnt.

RoboRobok started a new conversation How Often Would I Refresh The Offline Access Token In A Web App?

Let's say I create a simple YouTube bot, sending thumbs up to some videos. I have several YouTube accounts connected to my web app. We can assume here that in practice, there is at least one video to like every 5-10 minutes, but usually more often. My web app runs every 1 minute to fetch if there are new videos to like. If it finds them, it likes them all.

This is a dummy example, but I'd like to understand how in reality we refresh offline access tokens.

So I connect each of my Google accounts to my Google app via consent screen with access_type=offline and I store all my refresh tokens, one per account. Now, when would it make sense to get the access tokens, which in Google case live for 1 hour? Here are some strategies I can think of:

  1. Refresh access token with every request, which is once per one minute for every account. Don't store the access token anywhere but in a variable. The next cron flow (one minute later) will just generate new access token.
  2. Store access tokens' lifetime and with every new flow, check if it's fresh enough to work with it, giving it some margin. For example, if it has at least 3 minutes left, use it. Otherwise, generate new one and use it.
  3. Always try to use the access token and only refresh it on error. That means, don't keep track of anything, just brute force using whatever you have. If there's access denial, refresh the token.

Do any of these strategies make more sense than others? How is it done in real world web apps?

02 Jul
1 month ago

RoboRobok left a reply on Default Folder Loaded By Homestead

After some further testing I found out it just takes the first domain alphabetically. What I did after finding this out is editing ~/Homestead/Homestead.yaml to map aaa.test domain to the project I want to be the default in :

sites:
    - map: aaa.test
      to: /home/vagrant/code/cool-project/public

Now, going to http://192.168.10.10 or any *.test (since I have dnsmasq configured to route all *.test domains to 192.168.10.10) opens the project from /cool-project folder.

RoboRobok left a reply on Integrate Project Already Build Using Vuejs In Laravel

What do you mean by that? You have a frontend in Vue.js already and you want to create backend in Laravel?

RoboRobok started a new conversation Default Folder Loaded By Homestead

If we go to http://192.168.10.10, what makes Homestead decide which project to launch? It's pretty dumb to load anything instead of throwing an error, same goes with any domain mapped to 192.168.10.10, but missing in Homestead.yaml.

In my case, it loads one of the projects, but I have no idea what determines which one. The one it loads for me is not the newest, not the oldest, not first and not last in my ~/Homestead/Homestead.yaml.

Is it random or what?

RoboRobok left a reply on Homestead And Dnsmasq To Map All *.test Domains

It worked after macOS restart for some reason. Before, restarting dnsmasq didn't help. I also tried to restart macOS before and it didn't work neither, so I have no clue why it works now.

RoboRobok started a new conversation Homestead And Dnsmasq To Map All *.test Domains

Hi guys,

I used to have dnsmasq working in the past, mapping all *.test domains to my Homestead machine. This time I can't make it work on Mojave.

  1. I installed dnsmasq with Homebrew: brew install dnsmasq.
  2. In /usr/local/etc/dnsmasq.conf I put address=/test/192.168.10.10.
  3. I created /etc/resolver/test file and put nameserver 127.0.0.1 there.
  4. Not sure what to do with resolv.conf, I have nameserver 172.20.10.1 there (also tried 127.0.0.1).
  5. Running it with sudo brew services start dnsmasq.

It's not working though, trying for example ping -c 1 abc.test, but the answer is:

ping: cannot resolve abc.test: Unknown host

Any ideas?

13 Jun
2 months ago

RoboRobok left a reply on Single Page App On Homestead

I never know how to configure Homestead to keep my config when I update it.

RoboRobok left a reply on Single Page App On Homestead

I know that. My question is how to use index.html. I’m not using Laravel here.

RoboRobok started a new conversation Single Page App On Homestead

Hi guys,

I'd like to create a Single Page App and test it on Homestead server. Everything works fine if I use /public/index.php file - all URLs in my domain are being handled by this file - but how can I tell Homestead to use index.html instead?

08 Jun
2 months ago

RoboRobok left a reply on Allow To Login With Passwords

Just use another guard whenever needed.

RoboRobok left a reply on Start New Query Builder On Model's Table

I experimented a little and yes - the answer is getQuery()! It works perfectly fine (example using Invoice model):

$stats = Invoice::getQuery()
    ->whereBetween(DB::raw('date(issued_at)'), [$from, $to])
    ->groupBy('date')
    ->get([
        DB::raw('date(issued_at) as date'),
        DB::raw('sum(total_value) as total_value_sum')
    ]);

So it does exactly the same thing as replacing Invoice::getQuery() with DB::table((new Invoice)->getTable()).

They both, after using get() in the end, return an instance of Illuminate\Support\Collection and I can avoid weird transformation on the model itself. Selecting raw grouped values on the model feels just wrong.

Thanks @nash !

RoboRobok left a reply on Start New Query Builder On Model's Table

@JLRDW - To call a non-static method on it. How else would you get a table name?

RoboRobok left a reply on Start New Query Builder On Model's Table

I tried using query() method (as I said in the original post), but it just starts new query, still being Eloquent Query. Not sure if getQuery() method exists, I will check it out.

RoboRobok left a reply on Start New Query Builder On Model's Table

Okay, let’s go back to my original question, because we are going nowhere with that debate.

RoboRobok left a reply on Start New Query Builder On Model's Table

@JLRDW - You answered yourself - Active Record is used to make it easier. That also means it’s higher level. I really understand how it works, just think your naming convention is backwards.

RoboRobok left a reply on Start New Query Builder On Model's Table

@JLRDW - Scope will work, it’s just a little awkward, as it’s meant to narrow the query, not to do something completely different. But yeah, from practical point of view it will work.

I completely don’t get your understanding of high/low level. Eloquent is just as much high level as Doctrine. You use some weird definition. If class A serves to give more power to class B, it means that class A is higher level than class B. And that is clearly the case with Eloquent vs. PDO. The latter one is just a library to use SQL in a more convenient manner. Eloquent use composition relationship on PDO, so how can PDO be more high level?

RoboRobok left a reply on Start New Query Builder On Model's Table

Please try to re-read my question if you’d like to try to answer.

RoboRobok left a reply on Start New Query Builder On Model's Table

@JLRDW - Eee no? Eloquent is higher level that PDO, as it uses PDO under the surface.

RoboRobok left a reply on Start New Query Builder On Model's Table

@JLRDW - Why would you go so low level and use PDO though?

RoboRobok left a reply on Start New Query Builder On Model's Table

@NASH - As an example, I needed to get some stats, using groupBy and some raw things inside get(). It’s actually weird that it still returns models after using groupBy.

RoboRobok left a reply on Start New Query Builder On Model's Table

@JLRDW - Interesting idea. A little quirky, but interesting. Are you sure there is no built-in method doing that?

RoboRobok started a new conversation Start New Query Builder On Model's Table

Hi guys,

is there any helper method to start new Query Builder on Model's table? I need to return some raw data to get a pure Collection, not Eloquent Collection of models.

In other words, I'm looking for a helper returning DB::table((new MyModel)->getTable()).

I know there's a query() method on Model, but it doesn't do that. It just starts new Eloquent Query.

01 Jun
2 months ago

RoboRobok left a reply on Angular2+. What’s You’re Opinion?

Angular and Vue.js are alternatives, Angular being more complex solution. I'm personally not a fan of Angular. It's just not fun to use and Vue.js is more than enough for me in terms of comprehensiveness.

31 May
2 months ago

RoboRobok left a reply on Why So Many People Leave Whitespace In Their Images?

I don't rip off their images, I often need a logo of something. You wouldn't believe how hard is it to find a logo without the whitespace sometimes.

RoboRobok left a reply on Why So Many People Leave Whitespace In Their Images?

Any images used by the websites. Logos, icons, diagrams etc. Instead of having the margin/padding defined in CSS, they do it inside the image.

RoboRobok started a new conversation Why So Many People Leave Whitespace In Their Images?

This drives me crazy. Whenever I look for an image, half of them appear to have some kind of padding inside. Vector or raster - doesn't matter. Their canvas in just larger than needed, having the white or transparent background inside.

Why do people do that?

29 May
2 months ago

RoboRobok left a reply on Logging In Laravel

Yes, putting Log::info() in production can be useful in some cases. It all depends what kind of data you want to collect.

RoboRobok left a reply on Breadcrumb With Laravel API

There are some really cool packages doing exactly that. Just google laravel breadcrumbs and you should find the inspiration.

RoboRobok left a reply on How To Avoid Repeating Logic For Client- And Server-side?

To be honest I'm just asking from curiosity. I used to duplicate the code, but web sockets seems like a good idea. However, in some projects it could be an overhead to use web sockets just for this purpose. In a game, on the other hand, web sockets are useful to have anyway.

RoboRobok left a reply on How To Avoid Repeating Logic For Client- And Server-side?

Yes, I forgot to include that as one of the points. I'm not sure how instant are the responses in practice. For this purpose, the decent solution should provide 100% instant responses.