sutherland

Experience

94,280

77 Best Reply Awards

  • Member Since 2 Years Ago
  • 710 Lessons Completed
  • 2 Favorites

16th November, 2017

sutherland left a reply on Fresh Laravel Install Has Auth Folders • 6 days ago

The Auth folder is supposed to be included. The make:auth command is only included to quickly scaffold views and add the routes. I assume most people will have more customized views and possibly routes, but the actual auth mechanism is usually similar enough to always include a starting point.

10th November, 2017

sutherland left a reply on Timestamps Are Formatted As Carbon Objects, While SoftDelete Fields Are Not? • 1 week ago

The base eloquent Model class does it for created_at and updated_at. You could create your own parent Model that extends eloquent and include the deleted_at field, but then you'd need to modify all of your models to extend it. I'd just be explicit and add the $dates property to your models where needed.

https://laravel.com/docs/5.5/eloquent-mutators#date-mutators

sutherland left a reply on Timestamps Are Formatted As Carbon Objects, While SoftDelete Fields Are Not? • 1 week ago

You need to add the dates attribute to your Task model:

class Task extends Model
{
    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = [
        'created_at',
        'updated_at',
        'deleted_at'
    ];
}

6th November, 2017

sutherland left a reply on Vue.js V-for Help! • 2 weeks ago

If you're compiling your stylesheet with Sass you could do this:

.article-item__title {
    .article-item:nth-child(4n+1) & {
        background: green;
    }

    .article-item:nth-child(4n+2) & {
        background: pink;
    }

    .article-item:nth-child(4n+3) & {
        background: purple;
    }

    .article-item:nth-child(4n) & {
        background: blue;
    }
}

sutherland left a reply on Vue.js V-for Help! • 2 weeks ago

@joshgallagher24 yeah, definitely move it into a method if you go with the modulus, only gave the example that way for the sake of clarity

5th November, 2017

sutherland left a reply on Vue.js V-for Help! • 2 weeks ago

To answer your question as is, use the modulus (%) operator. Instead of using the index to directly pull an element from the array, I think you could use this in your article-item component:

:class="titleColors[index % titleColors.length]"

But honestly I'd just use the nth-child CSS selector or move that logic into the component that houses the article-items

27th October, 2017

sutherland left a reply on Laravel 5.1 Is Really Slow • 3 weeks ago

From the creator of Laravel himself, this might help you understand: https://medium.com/@taylorotwell/benchmarking-laravel-symfony-zend-2c01c2b270f8

16th October, 2017

sutherland left a reply on How To Display Data From My Pivot Table • 1 month ago

First thing you should do is simplify

// Unnecessary complexity
$ups = User::find(Auth::user()->id)->products()->get();

// Should be the same
$ups = Auth::user()->products;

Can you show what you get when you dd($ups)?

sutherland left a reply on How To Display Data From My Pivot Table • 1 month ago

Be sure to include this in your relationship

return $this->belongsToMany('App\Products')->withPivot('ip');

Then you can reference it like this:

foreach ($user->products as $product) {
    echo $product->pivot->ip;
}

sutherland left a reply on Include A Js File In Blade One-time-only After Used Has Logged In • 1 month ago

I don't know why you'd only want to include the file once, it should be cached after it gets loaded the first time.

Anyways, you can add the authenticated() method to your LoginController and flash a variable to the session:

   /**
     * The user has been authenticated.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  mixed  $user
     * @return mixed
     */
    protected function authenticated(Request $request, $user)
    {
        $request->session()->flash('show_script', true);
    }

and then in your template file check you can check for it

@if(session()->has('show_script'))
   <script>
      //
   </script>
@endif

14th October, 2017

sutherland left a reply on Can I Use Vue Js And Laravel Together? • 1 month ago

Yes! There is a series on here that should make it pretty easy: https://laracasts.com/series/learn-vue-2-step-by-step

sutherland left a reply on Detecting And Empty Model When Passed Via Route Model Binding • 1 month ago

You can check $profile->exists

sutherland left a reply on What Program Does Jeffrey Way Use To Record The Screencasts? • 1 month ago

Well he's on a Mac, I might be imagining it but at one point I think he said he uses Screenflow which I've used before. It isn't free, but Quicktime on a Mac has built in screen recording.

sutherland left a reply on Works On Desktop But Not Mobile • 1 month ago

Something must be setting a Content-Security-Policy HTTP header or your page has a tag in the head that looks something like this:

<meta http-equiv="Content-Security-Policy" content=" ... ">

This is basically a whitelist for the client to know what is safe to load and what isn't. Use the network inspector to check the headers if you can't find the meta tag. It needs to be updated to include data: for img-src.

13th October, 2017

sutherland left a reply on Profile • 1 month ago

@JeffreyWay he may be referring to the fact that after participating in a discussion with a name or comment containing something in curly braces, a profile will render for a split second before going blank.

After this thread anyone involved like myself or @Snapey or @martinbean will have a blank profile. I think it has to do with Vue trying to interpolate the braces.

sutherland left a reply on Works On Desktop But Not Mobile • 1 month ago

What type of mobile device?

On iOS you can go to Settings > Safari > Advanced and turn on the web inspector. Then connect the device to you computer via USB and launch Safari on your computer. Be sure "Show Develop menu in menu bar" is enbaled in your advanced settings. Open the page on your iOS device, then on your computer you should see the device listed in the develop menu, which should then show any open pages.

sutherland left a reply on Testing Image Upload But It Fails When I Add Validation Rule • 1 month ago

@andreich1980 @artka54 I think using mimetypes:image/jpeg,image/png is the best solution, because the mime type will always be the same regardless of file extension. I think when using image|mimes:jpeg,png Laravel will try to infer the mime type, which should work, but just isn't as explicit.

sutherland left a reply on {{ $Auth::User() }} Bug? • 1 month ago

@Snapey I've already submitted a PR. Since the with scaffolding will only ever display the current user, I don't think it's a big issue but it definitely should be added to set a good example.

sutherland left a reply on {{ $Auth::User() }} Bug? • 1 month ago

@Snapey I think you still misunderstand. He doesn't have that in his HTML output, it's in the default auth scaffolding. His report is about user inputted data, which we already established.

sutherland left a reply on {{ $Auth::User() }} Bug? • 1 month ago

You don't have to use the default js file at all. If you're using Bootstrap and that's the only javascript you need, just remove app.js and load jQuery and Bootstrap from a CDN.

sutherland left a reply on Login Verifcation • 1 month ago

Yes, you never want passwords stored in plain text. In 4.2 you need to use $password = Hash::make('secret'); when creating a user.

sutherland left a reply on Login Verifcation • 1 month ago

If none of the passwords are hashed, that's probably your problem. The passwords should not be in plain text, because Laravel will hash your user's input before checking if it matches the value in the database.

sutherland left a reply on {{ $Auth::User() }} Bug? • 1 month ago

@martinbean like I said, it's an unescaped user input problem. Vue tries compiling the page and sees the curly braces, it could be anything that isn't a variable and it would break.

sutherland left a reply on Login Verifcation • 1 month ago

Did you register the user correctly? Is their username hashed in the database?

sutherland left a reply on [5.5] Is There A Way To Turn Rendering Of HttpExceptions Off? • 1 month ago

Check out the class your exception handler is extending: https://github.com/laravel/framework/blob/5.5/src/Illuminate/Foundation/Exceptions/Handler.php

You can override any of the methods in your app/Exceptions/Handler.php file. Check out prepareException() and prepareResponse() for two methods that may be helpful to override.

sutherland left a reply on Login Verifcation • 1 month ago

Wow, 4.2 is over 3 years old and no longer supported, don't know why an instructor would be using it.

Anyways, what does your form look like? Is the username column actually uname in the database? What do you get if you dd($userdata); before the Auth::attempt?

sutherland left a reply on Login Verifcation • 1 month ago

The bacticks should be on their own line before and after.

But I do have to ask, if you're just getting started, why 4.2? Are you taking over an existing project?

sutherland left a reply on {{ $Auth::User() }} Bug? • 1 month ago

That's because everything is in <div id="app">...</div> which Vue wants to render by default. If you don't use Vue, don't include it in your compiled JS file. If you are using Vue and just don't want it to try to render user input, simply add the v-pre prop to elements that contain user submitted data.

<span v-pre>{{ this will not be compiled }}</span>

sutherland left a reply on How To Get Answers To The Questions ? • 1 month ago

@ChristophHarms @ejdelmonico I want to third the attitude. I think I've answered one of his questions before and on another where I tried to help and he managed to solve it on his own, he refused to say how. Participating in a support forum should be a two way street.

https://laracasts.com/discuss/channels/vue/axios-wrong-response-on-post

sutherland left a reply on Eloquent Collections, How To Modify The Data Of Each Registry Contained In Results? • 1 month ago

Because you are using the DB facade in getMobilesProducts, you aren't actually getting an instance of the model.

You need to change it to use the model instead.

public function getMobilesProducts()
{
    return \App\Product::orderBy('created_at')
        ->where('categoryName', 'All Cell Phones with Plans')
        ->where('regPrice', '<', 1000)
        ->get();
}

sutherland left a reply on How Create Column In Phpmyadmin? • 1 month ago

Read the error, users is already a table. Your migrations table is probably missing or out of sync with your database, because it's trying to run the migration that creates the users table when it already exists. If you're in Laravel 5.5 you can run php artisan migrate:fresh to clear everything.

sutherland left a reply on {{ $Auth::User() }} Bug? • 1 month ago

He's saying that if he displays the user input unescaped and it breaks.

The reason that it happens when you load the default app.js file is because Vue tries to render anything in {{ ... }} using their template engine, and obviously if it's a variable that doesn't exist you'll get an error. Try loading it again and look at your browser's javascript console and you should see the error.

12th October, 2017

sutherland left a reply on Eloquent Collections, How To Modify The Data Of Each Registry Contained In Results? • 1 month ago

If you can share a more complete example of your code I'd be happy to take a look.

sutherland left a reply on How To Fix Artisan? Php Artisan Optimize Throws A [ReflectionException] • 1 month ago

You have to compile the javascript without the user data. You should print the user object in your view template. Laravel does this for the CSRF token out of the box, you'll find this in the default app.blade.php file:

    <!-- Scripts -->
    <script>
        window.Laravel = {!! json_encode([
            'csrfToken' => csrf_token(),
        ]) !!};
    </script>

You could modify this to also include a user object:

    <!-- Scripts -->
    <script>
        window.Laravel = {!! json_encode([
            'csrfToken' => csrf_token(),
            'user' => $user->toArray(),
        ]) !!};
    </script>

Then in your compiled JS file you'd reference window.Laravel.user.id

sutherland left a reply on Problem With Custom Validation Rule • 1 month ago

Also, the make:rule command was added in Laravel 5.5, be sure the documentation you're viewing matches the version you're using. You can change the version in the top right corner of the docs page.

sutherland left a reply on Eloquent Collections, How To Modify The Data Of Each Registry Contained In Results? • 1 month ago

That's the way it should work. It sounds like you may be overcomplicating things.

sutherland left a reply on Login Verifcation • 1 month ago

Use three backticks (`) on the line before and the line after your code to make it display here.

sutherland left a reply on Problem With Custom Validation Rule • 1 month ago

You need to import App\Rules\Invateemails in your controller.

sutherland left a reply on Return Different Data To Search Bots? • 1 month ago

I would just provide a fallback pagination system for users that have JS disabled. It's also a good thing so that a user who finds one of your pages in a search result and clicks it, they're actually taken to a page with what they were looking for and not the beginning of the infinite scroll every time.

sutherland left a reply on Eloquent Collections, How To Modify The Data Of Each Registry Contained In Results? • 1 month ago

You were unable to implement a custom accessor, or you aren't allowed to?

All you'd need to do is put this on your Product model:

    public function getCalcPriceAttribute()
    {
        $x = $this->price; //eg 5
        $y = 4;
        $amount= $x + $y;
        return $amount;
    }

and then you can use it via

$product->calcPrice;

11th October, 2017

sutherland left a reply on Limit No Longer Works As Intended After Eager Loading? • 1 month ago

take() is just an alias of limit()

sutherland left a reply on Instantiating A Class (from A Laravel Package) Inside Of A Controller • 1 month ago

@lgochin because it's not namespaced, you should proceed the class name with a backslash.

$amz = new \AmazonOrderList("myProjectName");

sutherland left a reply on Limit No Longer Works As Intended After Eager Loading? • 1 month ago

I recommend installing Laravel Debugbar or Clockwork, both tools make it very easy to inspect things like queries, request data, or session data. I don't know the answer to your specific question, but seeing the queries being executed can help in a lot of situations, and those packages are much more convenient than enabling query logging yourself every time you want to debug something.

sutherland left a reply on Laravel 5.5 How To Broadcast A Resource?? • 1 month ago

Check out the source for the Resource class, you should be able to find something there: https://github.com/laravel/framework/blob/5.5/src/Illuminate/Http/Resources/Json/Resource.php

sutherland left a reply on Laravel 5.5 How To Broadcast A Resource?? • 1 month ago

Have you tried using return new UserResource($this->user)->toArray();?

sutherland left a reply on What's The Point Of A Custom Pivot Model? • 1 month ago

You can write logic or easily query the pivot table directly.

For your example, you might want to add a few methods on AccountSubscription to do things like extend the expiration date or cancel now. It would also make it easier to delete any AccountSubscription that expired more than a year ago. I assume you'd also be able to use custom mutators and accessors.

There's a lot you could use it for.

sutherland left a reply on Testing Image Upload But It Fails When I Add Validation Rule • 1 month ago

Either change it to 'image|mimes:jpeg,png' or 'image|mimetypes:image/jpeg,image/png'

sutherland left a reply on Let's Build A Forum Series - Handler.php • 1 month ago

Don't forget to mark as solved

Edit Your Profile
Update

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