Ruffles

Front End Developer at Cuponation

Experience

261,210

155 Best Reply Awards

  • Member Since 2 Years Ago
  • 867 Lessons Completed
  • 124 Favorites

26th March, 2017

Ruffles left a reply on Does Eloquent Prepare The Output Of The Data In The Collection When Relationships Are Eager Loaded? • 20 hours ago

The desired output would be:

stdClass => 
   'email' => [email protected]',
    // some other fields go here
   'roles' => [
      stdClass => [
          'name' => 'super_admin'
      ],
       stdClass => [
          'name' => 'client_manager'
      ]
   ]

this is how eloquent outputs the query but for some reason I get the following when I use the fluent query builder with joins:

[
    stdClass => [
       'email' => [email protected]',
        // some other fields go here
       'role_name' => 'super_admin'
    ],
    stdClass => [
       'email' => [email protected]',
        // some other fields go here
       'role_name' => 'client_manager'
    ],
]

Ruffles left a reply on Does Eloquent Prepare The Output Of The Data In The Collection When Relationships Are Eager Loaded? • 23 hours ago

My table schema is simple:

users table

id
email
password
...

roles table

id
name

role_user table

role_id
user_id

I am using the same schema from the package spatie/laravel-permission

25th March, 2017

Ruffles started a new conversation Does Eloquent Prepare The Output Of The Data In The Collection When Relationships Are Eager Loaded? • 1 day ago

Hello there!

I am working on this project where I use the Fluent Query Builder and I am trying to recreate the same output from the eloquent relationship eager loading, User::with('roles')->get() for example, with join statements.

As a result I had duplicate rows for obvious reasons. I had a list of repeating email addresses with multiple role names for a many to many relationship.

My question is: Do I have to manually structure the objects where I have a nested object(s) for the relationships?

25th February, 2017

Ruffles left a reply on How Can I Access Children Data From The Parent In VueJS2? • 1 month ago

To pass data from a parent component to a child component, use props. To pass data from a child component to a parent component use custom events.

Ruffles left a reply on "Real World" Example Of CRUD W/ Laravel & Vue (non SPA) • 1 month ago

Build components and use props to pass jsonified data (json_encode($projects)) to the component.

Example:

<projects-list :projects="{{ json_encode($projects) }}"></projects-list>

20th February, 2017

Ruffles left a reply on When Starting A New Project With Multiple Components Like Website, Admin Panel, API, Subscriber Panel Etc. How Do You Structure It? • 1 month ago

Building the project as packages might be useful but it has downsides like the need to update all packages every time you add new code in one of the packages.

19th February, 2017

Ruffles left a reply on Repository Pattern • 1 month ago

As far as I know, there's form (request) validation for that, but I am not sure if model validation is needed (maybe in some cases) before each database write operation.

17th February, 2017

Ruffles started a new conversation When Starting A New Project With Multiple Components Like Website, Admin Panel, API, Subscriber Panel Etc. How Do You Structure It? • 1 month ago

Hey there,

I am starting a new project and I am wondering if thinking about scalability is a good idea at the beginning when I have no idea about any stats.

So my question is:

When starting a new project which has multiple components like Website, Admin panel, Subscriber panel, API, iOS app, Android app and maybe a few more, do you:

  • Build them all as one Laravel application
  • Build an API in Laravel / Lumen and use front end frameworks like VueJS / Angular / AngularJS / React
  • Build each component in a different Laravel application, so you end up with like 4, 5 or maybe more Laravel applications which most of them will share the same features and / or models

15th February, 2017

Ruffles left a reply on Did I Lose My Search Privilege? • 1 month ago

CTRL + F5 (hard refresh) fixed it.

12th February, 2017

Ruffles left a reply on Essential Quals/experience For A PHP Developer? • 1 month ago

I would say that motivation and drive to learn and get better every single day is the most important skill you can have.

I would say that Laracasts is probably your best resource for Laravel which helped me to find a job and help colleagues. Oh and it's an amazing feeling when I can mention watching Laracasts videos on my LinkedIn profile as experience and colleagues at my first company say stuff like "Are you Ruffles from the Laracasts forums?!" :D Thanks @JeffreyWay

I learn mostly from video tutorials so I am subscribed to some other popular web development video tutorial platforms besides Laracasts.

I've also bought a few useful PHP / Laravel courses which I've learned a lot from (haven't touched Adam Wathan's book Refactoring to Collections and his course Test Driven Laravel yet).

I also watch conference talks to get some tips and tricks, help people on these forums here from time to time and I have a few books that I want to read but I have not found any free time to focus on them. Newsletters are piling up in my email and I read some of them.

Before I forget, I also learn a lot from working on real projects where I have to implement different features for clients. It taught me how to figure out stuff on the spot, by reading docs, googling and asking people on forums or the Larachat slack channel.

Maybe the Awesome Laravel list will help you find some resources.

Attending Laracon is not a bad idea, if you have the money and time to attend it. Laracon Online will be interesting.

I don't see much value in certificates really, because the technology is moving so fast and they might be useless after a while. Adopting a new technology quickly is more important than a certificate if you ask me.

25th January, 2017

Ruffles left a reply on Override Default Email For Password Resets In 5.4? • 2 months ago

You have to publish the vendor email template files by running php artisan vendor:publish --tags="mail"

Ruffles left a reply on Class 'App\Console\Carbon' Not Found? • 2 months ago

Add use Carbon\Carbon; at the top of the console command class.

Ruffles left a reply on Redis In Laravel - Password Protection • 2 months ago

Any ideas if I use Redis on AWS or any other hosting (except shared hosting)?

24th January, 2017

Ruffles left a reply on Redis In Laravel - Password Protection • 2 months ago

@ohffs How would you deploy Redis in production?

21st January, 2017

Ruffles left a reply on Can't Laracast Be Free? :( • 2 months ago

Maybe if Jeffrey implements a "Donate a subscription for a person who wants to level up", it would be cool.

18th January, 2017

Ruffles left a reply on Bug On Laracasts • 2 months ago

What about caching?

17th January, 2017

Ruffles left a reply on I'm Starting To Hate Laravel • 2 months ago

Wow, sorry man, that sucks. It can be frustrating sometimes when you don't know how to find the solution but the tool is not really the problem most of the times.

I remember having to build a real-time chat and it took me about 4 months to finish a basic functionality, but I realized that the idea I was going about it was bad, not the tools I use. At one point I was completely stuck and didn't know what to do next, but I found a solution thanks to the community.

Calm down and try again. Feel free to ask people either here on the forums or the Larachat slack community.

5th January, 2017

Ruffles left a reply on Laracasts AutoSubscription • 2 months ago

You haven't really understood the word subscription.

When you signed up to Laracasts, didn't you read the plan names? It clearly states monthly and yearly and that means that you will pay every month for the service to be able to watch the videos.

The subscription model is not a one-time thing and you are done. You have to cancel the subscription right after you pay for the month in order for you to stop the payment process next month / year. You'll still have access to the videos for that month but you won't be billed next time.

Only the forever plan is a one-time payment and you will have access to all of the videos forever.

If you are not happy and want to ask for a refund, send Jeffrey a support message by clicking on the support link in the footer of the page.

Ruffles left a reply on Remove Public From URL Api Lumen • 2 months ago

No. that's the PHP server and it's only used in development.

4th January, 2017

Ruffles left a reply on Remove Public From URL Api Lumen • 2 months ago

Laravel / Lumen and shared hosting are not exactly best friends. For Laravel / Lumen apps, you need to be able to have full SSH access and complete folder structure control, also known as your own server.

Last time I tried to add a Laravel project on shared hosting, it ended up being way too limited and I was able to add the project files in the public_html folder which ruined the URL paths.

Some shared hostings might allow full SSH access and folder access, but you have to check that in the features they offer.

30th December, 2016

Ruffles left a reply on Throttling / Spacing Out Jobs • 2 months ago

The first thing that comes to mind is to add a separate queue listener specifically for the queue that processes the requests and after each job is processed, restart the queue listener and add a different delay (the --delay option) on each restart.

I know it's not the smartest idea but it might work temporarily. Can't think of any other way to set a different delay in runtime.

Personally, I haven't tried it but I know that when the queue listener stops working, you restart it and the job that is next in the queue will jump on try 2 (if it stopped on try 1 for example) and will be reprocessed again.

I've noticed this when I had a problem with the queue listener docker container in development. It suddenly stopped working for some reason, so I had to restart it completely.

29th December, 2016

Ruffles left a reply on /logout Does Not Exists • 2 months ago

It's in the Illuminate/Routing/Router class, the auth() method.

27th December, 2016

Ruffles left a reply on Return Response From Controller Based On A User's Role Laravel 5.3 • 2 months ago

$users = auth()->user()->hasRole('admin') ? getAllUsers() : getUsersForThatOrganization();

return view ('users.index', compact('users'));

This code assumes that only admin and organization_admin roles have access to the users route.

Ruffles left a reply on Creating A Laravel Web Client From An Internal Laravel API • 2 months ago

You have a few options:

  1. Build the API and the mobile and web clients will use it fully (the front end will be some kind of single page application). [Recommended]
  2. Build a traditional web client which won't use the API at all but it will use/share almost all of the features that the API has. (Same or differe
  3. Use 2 different projects for the API and the web client and run requests from the web client to the API using Guzzle or something similar. (this will count as external API) [Not Recommended]

I recommend the first approach because you are already building an API, so why not use it fully for all clients? It might require a little bit extra JavaScript knowledge and understanding of the front end world, but you won't need to reimplement the same features twice.

Ruffles left a reply on How Type Hinting Works? / Type Hinting With Own Class • 2 months ago

You are missing a $shipment_id variable as a parameter in your show() controller method.

You have to pass that shipment ID to the class somehow, maybe through a named constructor?

Ruffles left a reply on Vue Js Or React Js For Laravel • 2 months ago

When choosing a framework or technology for a project, research the following things:

  • How big is the community and can I find people to help me when I am stuck?
  • Are there any learning resources?
  • Will it be easy for me and my team to work with it?
  • Maybe a few more similar questions

Laravel can work with any framework, but it's up to you to choose which one you should work with, because at the end of the day, you will work on that project, we won't.

25th December, 2016

Ruffles left a reply on New To Laravel - Is This The Right Approach For Learning Laravel & Side Project Goal? • 3 months ago

I'd suggest to you to start with the following list:

Jeffrey will record a new Laravel 5 from scratch series when Laravel 5.4 comes out (most likely next month) so you will have to check the documentation about some things while following some of the examples.

Remember to rewatch some of these videos to understand the concepts better.

After you are done with this list of series, you can start looking at individual features of the framework in the What's new in 5.* or Intermediate Laravel.

Have fun!

22nd December, 2016

Ruffles left a reply on Laravel 5.3 - How Do I Delete Rows Depending On The Selected Checkbox? • 3 months ago

Send the selected IDs as an array to the server using <input name="dosier_ids[]"> and on the server, just do something like Dosier::whereIn('id', request()->get('dosier_ids'))->get()->delete();

21st December, 2016

Ruffles left a reply on Laracasts Subscription Bug • 3 months ago

Click on the Support link in the footer of the page and send a message to Jeffrey about your story.

Ruffles left a reply on Laravel 5.3 With AngularJS 2.0 • 3 months ago

  1. Create a new Laravel project,
  2. Build the API
  • Setup CORS (if you host the apps on different domains)
  1. Create an Angular 2 project and set it up.
  2. Build the front end
  3. Host the apps on a server somewhere.

19th December, 2016

Ruffles started a new conversation How Can I Increase The Session Lifetime For Unauthenticated Users (guests) When They Browse A Website? • 3 months ago

Hello!

I am looking for a way to increase the lifetime of the session based on the clause if the user is authenticated or not. I am keeping some data in the session for tracking purposes and I want it to be longer than 2 hours.

I know about the session_lifetime option in the config files but that won't help because in this case, that number should be dynamic.

Any ideas how can I do that dynamically in runtime?

18th December, 2016

Ruffles left a reply on Deleting A Migration • 3 months ago

You can delete the file and the record with the same filename from the migrations table and it should not cause any troubles.

Ruffles left a reply on Api Attributes • 3 months ago

It's not bad but it might cause bugs in some cases.

Read this article for more information

Ruffles left a reply on Api Attributes • 3 months ago

I'd go with transformer classes using Fractal, and modify the response of the model in a way that I can add data which the model itself does not have.

16th December, 2016

Ruffles left a reply on Laravel Socialite Throws A Fatal Error When I Cancel The Authorization Process With Facebook • 3 months ago

That means, the $user variable is empty and you are not reassigning it if it's null so just reassign it to the User::create() part and it should work.

14th December, 2016

Ruffles left a reply on Laravel Socialite Throws A Fatal Error When I Cancel The Authorization Process With Facebook • 3 months ago

Add it before the try catch block.

13th December, 2016

Ruffles left a reply on Laravel Socialite Throws A Fatal Error When I Cancel The Authorization Process With Facebook • 3 months ago

yup, before getting the user() data.

Ruffles left a reply on Laravel Socialite Throws A Fatal Error When I Cancel The Authorization Process With Facebook • 3 months ago

Yeah, I didn't check the request at all to see what's returned but someone on Larachat helped me solve this problem.

All I had to do before getting the user and handle the request was to add the following code in the callback method:

if (!$request->has('code') || $request->has('denied')) {
    return redirect('/');
}

12th December, 2016

Ruffles started a new conversation Laravel Socialite Throws A Fatal Error When I Cancel The Authorization Process With Facebook • 3 months ago

Hey,

I am trying to implement Facebook authentication with Laravel Socialite and I've mostly done all of it, but now I have a problem when the user cancels the authorization process on the facebook page.

The problem is, when I click on the "Cancel" / "Not Now" button, I am redirected back to my facebook callback route and I get the following error:

GuzzleHttp \ Exception \ ClientException (400)
Client error: `POST https://graph.facebook.com/oauth/access_token` resulted in a `400 Bad Request` response: {"error":{"message":"Missing authorization code","type":"OAuthException","code":1,"fbtrace_id":"AkLoGvbv7tn"}}

Any ideas what could be the problem or how to deal with it?

Ruffles left a reply on How To Change The General Uncaught Exception JSON Response? • 3 months ago

I am still looking for a way to override the uncaught exception JSON responses based on our team's rules. If I don't do that, the mobile apps will break because of their error handling patterns.

From the uncaught fatal exception JSON response example in the opening post, I want to change it to something like:

{
    "status_code": 500
    "status": "error",
    "message" => "An error has occurred and this resource cannot be displayed."
}

Also, I forgot to mention that I am using graham-campbell/exceptions

Any ideas how can I do that?

10th December, 2016

Ruffles left a reply on How To Define Constants In LUMEN • 3 months ago

Create a class (maybe a model) and put the roles there.

Example:

Role.php

class Role 
{
    const ADMIN = 1;
    const MEMBER = 2;
    const SUBSCRIBER = 3;

    public function someMethod(){}

}

You can use these constants in your controller like so:

class SomeController extends Controller 
{
    public function someMethod() 
    {
    // some example query to demonstrate how to use the constants from the Role class.
         $admins = User::roles()->where('role', Role::ADMIN)->get();
    }
}

Don't forget to import the Role class at the top of the controller file with the use statement.

4th December, 2016

Ruffles left a reply on How To Count User Logins? • 3 months ago

A better idea would be to use Redis for this type of counting, it won't affect the performance of your database.

Ruffles left a reply on Anuglar 2 Tutorial • 3 months ago

Everything is possible!

3rd December, 2016

Ruffles left a reply on Lost Trying To Implement Authentication • 3 months ago

tymon/jwt-auth might help you with your API authentication problems.

24th November, 2016

Ruffles left a reply on 40% Off Sale Not For Existing Subscribers? • 4 months ago

Switch the subscription to Lifetime, apply the coupon and press update.

Ruffles left a reply on How To Change The General Uncaught Exception JSON Response? • 4 months ago

I have the following code in the render method:

/**
     * An array of friendly exception messages corresponding to their exception.
     *
     * @var array
     */
    protected $exceptionMessages = [
        TokenMismatchException::class        => "The session expired, please refresh the page and try again!",
    // and a few more....
    ];

// public function render($request, Exception $e) 

foreach ($this->exceptionMessages as $exception => $exceptionMessage) {
   if ($e instanceof $exception) {

          if ($request->ajax() || $request->wantsJson()) {
               return response()->json([
                   'status_code' => Response::HTTP_INTERNAL_SERVER_ERROR,
                   'status'      => 'error',
                   'message'     => $exceptionMessage
               ], Response::HTTP_INTERNAL_SERVER_ERROR);
          }

          flash()->error($exceptionMessage);

          return back();
    }
}

return parent::render($request, $e);

That's how I deal with the known exceptions, but that's not exactly the full list of exceptions.

Ruffles left a reply on How To Change The General Uncaught Exception JSON Response? • 4 months ago

That's what I am already doing but for specific exceptions only.

Ruffles started a new conversation How To Change The General Uncaught Exception JSON Response? • 4 months ago

Hey there!

I am building an API for this application that I am working on, and I have a few Exceptions handled in the Handler class, but because I don't know all of the possible ones, I just want to override the default JSON response by PHP/Laravel, which looks like this:

{
  "errors": [
    {
      "id": "e7b05e79-4aef-4380-b978-59448baaa633",
      "status": 500,
      "title": "Internal Server Error",
      "detail": "An error has occurred and this resource cannot be displayed."
    }
  ]
}

Any ideas how can I do that?

Ruffles left a reply on Seperate Roles In Different Models Or Use Only User? • 4 months ago

They are all users, but they have different roles. No need for extra model classes unless you have extra tables for each role where they have uncommon data and you need to access specific data for each type of user aka user role.

Ruffles left a reply on Laravel Project As A Service? • 4 months ago

Keep all of the domains in the database and set a wildcard subdomain. When the registered user / company accesses their domain, you would check if the logged in user has access to that domain, and if it does, you load the data for that user and let them access your application / their own part of the application.

You'll have to think a little bit more about how you want to structure things.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.