sutherland

Experience

115,680

106 Best Reply Awards

  • Member Since 3 Years Ago
  • 748 Lessons Completed
  • 2 Favorites

24th February, 2018

sutherland left a reply on A Bit Deep On API Resources Issue • 1 day ago

'brand' => new BrandResource($this->brand) should work

23rd February, 2018

sutherland left a reply on Pass A Property Parameter To The Vue Component • 2 days ago

Are you using Vue devtools? If you aren't getting any console errors you should use it to check what data is set in the component.

sutherland left a reply on Pass A Property Parameter To The Vue Component • 2 days ago

When you do active_tab === login you aren't comparing it to the string, try this:

<b-tab title="Login" :active="active_tab === 'login'">
<b-tab title="Register" :active="active_tab === 'register'">

21st February, 2018

sutherland left a reply on Relationships For Multiple Value Of Foreign Key In Same Column • 4 days ago

It should only take a few minutes to write a query that would convert your existing data to use a pivot table, and then it doesn't matter if you have 100 rows or 100,000 rows of data. You'll probably save yourself future headaches this way.

20th February, 2018

sutherland left a reply on Relationships For Multiple Value Of Foreign Key In Same Column • 4 days ago

You should use a pivot table with a many to many relationship. Here's an example structure:

products

  • id
  • name

city

  • id
  • name

city_product

  • city_id
  • product_id

19th February, 2018

sutherland left a reply on Cant Use Laravel Mix • 6 days ago

Sounds like your CSS still reference bootstrap-sass but it's not included in your NPM dependencies. Run this and try again:

npm install bootstrap-sass --save-dev

sutherland left a reply on Resource Vs ResourceCollection • 6 days ago

I believe ResourceCollection is not really meant to transform the models themselves, but to include the metadata like pagination links, collection size, etc. And you don't usually need to include that metadata on an endpoint where you only ever expect one result.

And what about when your models have relationships? Say you have a movie and it has a director you want to include as a child property. Well, you don't need pagination on the director property and instead of writing the logic to transform the director in the MovieResource, you can write a DirectorResource that can be reused for different endpoints.

sutherland left a reply on Wordpress, Forge & Version Controlled WP Themes • 6 days ago

Create it as a general PHP site and once it's linked to your repo it should deploy everything as you'd expect.

sutherland left a reply on Type() Vs Value() In Dusk • 6 days ago

Yes, it is intended to work that way. Best thing to do in a case like this is look at the source. Here is the value() method where you can see it accepts a selector and sets the field value directly via JS. Here you can see the type() method which doesn't accept a selector and sends the individual keystrokes.

Using type() will help emulate exactly what happens when typing something into a field. Like you said, it will trigger change and keyup events that using value() won't. Your field will almost always have a name so it's just more convenient to only have to specify that.

Using value() could be helpful in more advanced situations where you might want to simulate part of your application programmatically setting the value of another field.

sutherland left a reply on Wordpress, Forge & Version Controlled WP Themes • 6 days ago

You should check out Bedrock, it lets your handle your entire WP site using composer.

15th February, 2018

sutherland left a reply on Validate The Query String • 1 week ago

I think you should be able to validate GET routes just like you would a POST.

sutherland left a reply on Json_encode Returns Boolean As String • 1 week ago

Have you tried attribute casting? Just define which properties are what type.

sutherland left a reply on Accessing Methods Through Relationships • 1 week ago

Which method did you go with? If you went with my first suggestion you could create a user relation on your suspension model, then use it to call the method on the user model when lifting the suspension:

public function lift($date = null)
{
    $this->user->setStatusToActive();

    return $this->update(['ended_at' => $date ?: $this->freshTimestamp()]);
}

sutherland left a reply on How Can I Solve "Connection Could Not Be Established With Host Smtp.gmail.com"? • 1 week ago

@moses that's because your local IP address is different than your server's IP. Your home IP is unlikely to get flagged by Gmail for spam, but you never know what your server's IP was previously used for.

14th February, 2018

sutherland left a reply on How Can I Solve "Connection Could Not Be Established With Host Smtp.gmail.com"? • 1 week ago

Use Mailgun, Amazon SES, or some other sending service. Your server's IP may have been associated with spam in the past and be blocked by Gmail.

sutherland left a reply on Accessing Methods Through Relationships • 1 week ago

What is the error you get?

My guess is that because suspensions() is a hasMany relationship you'r calling lift() on a collection instance instead of the model instance.

sutherland left a reply on Old Value For Input With Array Form Name • 1 week ago

@simti it's a good idea to post the solution to your problem even if you solve it yourself, might help future users.

13th February, 2018

sutherland left a reply on VUE With Laravel • 1 week ago

You're binding your Vue instance to the first match for the '#edit-recipe' CSS selector. You'll want to bind it to a parent element like an '#app' that contains everything on your page.

sutherland left a reply on Redirect User To The Create New Post Page After The User Fill In The Login Form In The Create New Post Page • 1 week ago

At the top of your LoginController you need to add

use Illuminate\Http\Request;

sutherland left a reply on Write This As One Method • 1 week ago

To expand on @arthurvillar's answer, you can check the request method in your request class if you need to conditionally add rules depending on whether it's a POST or PATCH request.

    public function rules()
    {
        $rules = [
            'first_name' => 'required|max:255',
            'last_name' => 'required|max:255',
        ];

        if ($this->isMethod('POST')) {
            $rules['referral'] = 'required';
        }

        if ($this->isMethod('PATCH')) {
            $rules['field'] = 'required';
        }

        return $rules;
    }

Not sure if this is a good practice or not but I've found it useful in a few cases.

12th February, 2018

sutherland left a reply on Migration String Length • 1 week ago

I think it will be 255 but you can provide a second argument to change it.

9th February, 2018

sutherland left a reply on Overwrite Default Notifications • 2 weeks ago

You need to add this method to your User model and just replace ResetPasswordNotification with your notification class:

    /**
     * Send the password reset notification.
     *
     * @param  string  $token
     * @return void
     */
    public function sendPasswordResetNotification($token)
    {
        $this->notify(new ResetPasswordNotification($token));
    }

28th January, 2018

sutherland left a reply on Auto Increment Model ID Per User • 3 weeks ago

You'd think semantically each page_id would be per user

I wouldn't think that, and I don't think there's any reason you should do it that way. What if you want an admin to be able to edit any page? When an admin visits /page/edit/1 are they going to be editing their own page 1 or someone else's? Users aren't going to be typing in the address manually and they aren't going to be confused that their next page isn't +1. In fact, I think if someone accidentally sent another user a link to /page/edit/1 it would be confusing that it takes them to edit a completely different page instead of telling them they aren't authorized to edit that page.

sutherland left a reply on . Env File I Changed DB Name But Not Reflected • 3 weeks ago

Have you tried running php artisan config:clear?

20th January, 2018

sutherland left a reply on Always Redirect To Single Route After Login • 1 month ago

I agree with @shez1983, but if you really want to you can override sendLoginResponse() on your LoginController to

    protected function sendLoginResponse(Request $request)
    {
        $request->session()->regenerate();
        $this->clearLoginAttempts($request);
        return $this->authenticated($request, $this->guard()->user())
                ?: redirect($this->redirectPath());
    }

19th January, 2018

sutherland left a reply on How To Sanitize Data With Axios In Laravel5.5/vue.js App • 1 month ago

If you submit a standard form the data is not sanitized on the front end either. It doesn't need to be.

You should always do sanitizing/validation on the backend (Laravel does this for you with Eloquent) since a user can edit the request you send and then consider if you want to do any sanitizing/validation on the front end.

18th January, 2018

sutherland left a reply on How To Do Axios Request In Laravel? • 1 month ago

If you're making a request to some URL that's on a different domain than the page requesting it, the page being requested will need an Access-Control-Allow-Origin header or the browser will block the request.

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

17th January, 2018

sutherland left a reply on Json_encode() • 1 month ago

It will format the $message variable as JSON so it can be used by JavaScript on your page. It could be used for a lot of things so impossible to know without more context.

Laravel will even let you return an Eloquent model or collection from a controller and format it as JSON for you automatically to consume your data as an API.

16th January, 2018

sutherland left a reply on Get The Latest Message Of Chat Model With MySQL. Just Cannot Get The Idea How To Do This. • 1 month ago

I think I see what you're asking now, and I think it would require a fairly complex query. My first instinct would be to try using groupBy() but then you'll still get two messages for each conversation: the latest where the user is the sender and the latest where the user is the receiver.

If it's not impossible to change your schema I'd recommend adding a Conversation model and make it so that a message belongs to a sender and to a conversation, and use a many to many relationship to assign users to a conversation.

sutherland left a reply on Git Workflow: Is It Possible To Pull Local Database Structure Into A Live Website? • 1 month ago

This is why Laravel (as well as other frameworks) use migrations. You can set up hooks to automatically run migrations when code is deployed.

sutherland left a reply on Get The Latest Message Of Chat Model With MySQL. Just Cannot Get The Idea How To Do This. • 1 month ago

Well you can change ->get() to ->first()

sutherland left a reply on Authentification Field Customization • 1 month ago

I think the method should be named username regardless of what field you're mapping it to, so it should look like this:

public function username()
{
    return 'phone';
}

sutherland left a reply on Get The Latest Message Of Chat Model With MySQL. Just Cannot Get The Idea How To Do This. • 1 month ago

Assuming you have an Eloquent model name ChatMessage, this should work:

$message = ChatMessage::latest()->where('sender_id', 1)->get();

15th January, 2018

sutherland left a reply on Laravel 5.5 - Is Debugbar Working After Login For Anyone? • 1 month ago

I don't have a fix to recommend but I can recommend Clockwork as an alternative. Didn't have the same problem but I switched to it from debugbar and it does the job.

7th January, 2018

sutherland left a reply on REST API Versioning • 1 month ago

I think worrying about a service provider impacting performance of your app would be a bit of premature optimization. Do you have any figures on how it affects your application's performance or are you making a guess?

sutherland left a reply on Want To Ask About Gmail! Halp! • 1 month ago

@larafam I believe G Suite is free for universities

sutherland left a reply on Want To Ask About Gmail! Halp! • 1 month ago

It's called G Suite. It's $5 per user per month, and once you sign up it will walk you through configuring your domain to be usable with Gmail.

5th January, 2018

sutherland left a reply on Insert Array As New Value In Database Table • 1 month ago

You just need to use PHP's explode function. Here's an idea:

// The user input
$input = 'one,two,three';

// Convert to an array
$items = explode(',', $input);

// This is where you insert your data.
// You could also use the query builder to insert all at
// once, but I do one at a time so I can track model events.
foreach ($items as $item) {
    \App\Item::create(['name' => $item]);
}

2nd January, 2018

sutherland left a reply on Laravel Uploading File - Creating Default Object From Empty Value • 1 month ago

You don't have a $Shipment_Attachmentvariable, you should have something that looks more like this:

Shipment_Attachment::create([
    'attachment_path' => $path,
    'attachment_body' => request('Description'),
    'attachment_visibility' => request('Visibility'),
    ...
    'user_id' =>  Auth::id()
]);  

19th December, 2017

sutherland left a reply on Profile Activity Feed Doesn't Display Message After Edits • 2 months ago

Could it be that a user's activities are stored as database notifications and the text displayed is read from data stored on the notification instead of directly off the related model?

18th December, 2017

sutherland left a reply on Sending Mail On AWS • 2 months ago

I think I've read somewhere that AWS will have to whitelist an EC2 instance if you want to send email from it. Probably a good move on their part to focus on SES deliverability and cut down on spammers abusing their network. There's going to be a bit of inconvenience but that's the cost of ensuring most mail clients don't send your message to spam.

sutherland left a reply on Queued Notifications • 2 months ago

Nice, glad that was it.

sutherland left a reply on Laravel 5.5 Disable Auto Login After Registration • 2 months ago

You need to be sure to add these use statements at the top of your controller file:

use Illuminate\Http\Request;
use Illuminate\Auth\Events\Registered;

Yes, I'm sure. I'm looking at the source code. https://github.com/laravel/framework/blob/5.5/src/Illuminate/Foundation/Auth/RegistersUsers.php

sutherland left a reply on Delete-product-functionality: MethodNotAllowed Error • 2 months ago

The way you are linking to the route is performing a GET request, but you've defined it as a delete request.

You'll need something like this:

<div class="col-sm-2">
    <a href="{{ route('products.destroy', $product) }}"  
        onclick="event.preventDefault();
        document.getElementById('delete-product-{{ $product->id }}').submit();">
        <h5>Delete</h5>
    </a>

    <form id="delete-product-{{ $product->id }}" action="{{ route('products.destroy', $product) }}" method="POST" style="display: none;">
        {{ method_field('DELETE') }}
        {{ csrf_field() }}
    </form>
</div>

sutherland left a reply on Queued Notifications • 2 months ago

I think you need to define the property on your Echeancetocome class, so it would start something like this:

class Echeancetocome extends Notification implements ShouldQueue
{
    use Queueable;

    public $bailarr;

...

sutherland left a reply on Sending Mail On AWS • 2 months ago

SES is really only for sending emails, so your MX records will still be set to whatever email service you want to use.

sutherland left a reply on Laravel 5.5 Disable Auto Login After Registration • 2 months ago

In your RegisterController, add the following method to override the default behavior:

    /**
     * Handle a registration request for the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function register(Request $request)
    {
        $this->validator($request->all())->validate();

        event(new Registered($user = $this->create($request->all())));

        // $this->guard()->login($user);

        return $this->registered($request, $user)
                        ?: redirect($this->redirectPath());
    }

You'll see the line I've commented out and can delete it if you'd like.

sutherland left a reply on SSL Lock Is Not Showing Except Homepage • 2 months ago

Be sure the APP_URL you have in your .env file is set as your https URL.

sutherland left a reply on Attempt To Assign Property Of Non-object In Controller Store Method • 2 months ago

Here's another solution:

$configuration = array_merge($this->validate(request(), [
      'device_name' => 'required',
      'sn' => 'required'
]), [
      'sntimezone => '+4'
]);

sutherland left a reply on Attempt To Assign Property Of Non-object In Controller Store Method • 2 months ago

Your $configuration variable is array, so assign the value using array notation like so:

$configuration['timezone'] = "+4";
Edit Your Profile
Update

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