sutherland

Experience

127,960

115 Best Reply Awards

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

5th March, 2018

sutherland left a reply on .env File Changes • 6 months ago

Yes, you'll notice there's also a config:cache command. Your setup must be doing this for you. Laravel does this for performance reasons. This combines all the configuration settings into a cached file to save a little time on every request. You can learn more here: https://laravel-news.com/config-caching

1st March, 2018

sutherland left a reply on I Run Composer Update On 5.5 After Adding Some Packages In Composer.json Got Problem With That... • 6 months ago

Looks like you need to require a newer version of graham-campbell/markdown compatible with 5.5. Try "graham-campbell/markdown": "^10.0",

sutherland left a reply on Dispatch Another Job From Within Current Job • 6 months ago

Great! Don't forget to mark your question solved.

sutherland left a reply on Do I Need To Include Doctrine/dbal In Composer For Laravel 5.5 And Above? • 6 months ago

If you already have a migration that modifies existing columns, yes, add it. If not, I'd wait until I need it to add it again.

sutherland left a reply on Do I Need To Include Doctrine/dbal In Composer For Laravel 5.5 And Above? • 6 months ago

A fresh installation of 5.5 doesn't require it. You may have previously used it because if you want to modify columns in a migration it is an additional requirement.

sutherland left a reply on Dispatch Another Job From Within Current Job • 6 months ago

Try running php artisan queue:work --tries=3 and then if the job is failing it will get pushed to your failed jobs table where you can see the stack track for why it's failing.

sutherland left a reply on Dispatch Another Job From Within Current Job • 6 months ago

I think you need to declare the ids property on your SendPush class:

...

class SendPush implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $ids;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($ids)
    {
        $this->ids = $ids;
    }

...

sutherland left a reply on Amazon S3 Region Problem • 6 months ago

The disks section should have another entry for s3 like:

    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_KEY'),
            'secret' => env('AWS_SECRET'),
            'region' => env('AWS_REGION'),
            'bucket' => env('AWS_BUCKET'),
        ],

    ],

sutherland left a reply on Amazon S3 Region Problem • 6 months ago

@splendidkeen check your config/filesystems.php file to see which env values are being read.

sutherland left a reply on Destroy Route Link • 6 months ago

What I do if I'm not going to use javascript is create a blade component that contains the form to clean up my table and so I can reuse the delete button in other parts of the application.

sutherland left a reply on My Laravel Is More Than 1GB In Size • 6 months ago

Are you running a process that creates that zip file? What does it look like? You might be including the previous zip in your new zip, making the result grow every time it gets zipped.

sutherland left a reply on My Laravel Is More Than 1GB In Size • 6 months ago

You might be storing something somewhere other than your storage directory. I would open your project root in your terminal and run du -sh * to get a summary of the size of each subdirectory, and from there drill down into which is using a lot of space.

sutherland left a reply on How To Run A Function Every Time A Certain Class Is Deleted? • 6 months ago

No, you don't need to return anything.

You're making it a little more complicated than necessary, here's closer to what you should do:

Page::deleting(function ($page) {
    foreach ($page->drawings as $drawing) {
        $drawing->delete();
    }
});

Drawing::deleting(function ($drawing) {
    $path = app()->basePath() . '/public' . $drawing->path;

    if (file_exists($path)) {
        unlink($path);
    }
});

sutherland left a reply on Blade HasSection, What Is It Really? • 6 months ago

You would use it in a master blade file so that a child template could optionally something like include a sidebar, hero image, or other element that might get reused in a few child templates but not in every single one.

If you placed the example given in your master blade file (something like app.blade.php), then in a layout that extends that view (like a home.blade.php) you could use

@extends('app')

@section('navigation')
    Some navigation content
@endsection

@section('content')
    The page content
@endsection

Next you could create another view that doesn't include the navigation section and blade will know not to render anything inside @hasSection.

sutherland left a reply on How To Run A Function Every Time A Certain Class Is Deleted? • 6 months ago

@octoxan no, I'd still call $drawing->delete() and make another listener/observer for the Drawing that does the file deletion. That way you don't end up having to repeat the logic in multiple places if a user needs to delete a single drawing without deleting the entire page.

sutherland left a reply on How To Get A File From A Url And Push To S3 Bucket On Behalf Of A User Account? • 6 months ago

You could just use the AWS SDK directly instead of the Laravel filesystem which I'm not sure can change s3 credentials on the fly. The linked repo has a demo for adding a file to S3.

sutherland left a reply on MassAssignmentException Error On Field After Form Submission • 6 months ago

Three backticks on a separate line before and a line after your code

```

sutherland left a reply on Vue Transition - Content Of V-for Displaying Before Container Transition Completes. • 6 months ago

Haven't used Vue transitions but it looks like you just need to add overflow: hidden; to the CSS of the parent element.

sutherland left a reply on How To Run A Function Every Time A Certain Class Is Deleted? • 6 months ago

@mrbadr observers are just another way to tie into the same Eloquent events, but like I said you'll need to listen to the Page's model events first to call delete on each Drawing. Otherwise the Drawing's deleting event (regardless of how it's registered) never gets called if it's left solely to the database schema.

sutherland left a reply on How To Run A Function Every Time A Certain Class Is Deleted? • 6 months ago

You are going to have to loop through the drawings somewhere and individually call delete on them if you want it to get rid of the files. I wouldn't do it in the controller, instead I'd listen to the deleting event on the Page model then individually delete each Drawing model. That way it will always delete the related records no matter where you call $page->delete() from.

https://laravel.com/docs/5.6/eloquent#events

28th February, 2018

sutherland left a reply on How To Find Nearest Cities From Latitude And Longitude • 6 months ago

Change it to City::selectRaw('id, latitude, longitude, (...))

27th February, 2018

sutherland left a reply on How To Save Quill.js Values To Database Laravel 5.6 • 6 months ago

@Drfraker well he had already replied to the wrong information, in that scenario I personally think it's better to post your new suggestion in a new comment so there's a record of what solutions have been tried and eliminated.

sutherland left a reply on How To Save Quill.js Values To Database Laravel 5.6 • 6 months ago

@Snapey it looks like @Drfraker changed his answer to mine after I posted

sutherland left a reply on How To Save Quill.js Values To Database Laravel 5.6 • 6 months ago

Quill has a demo of submitting a form on their playground, looks like you'll need a bit of javascript: https://quilljs.com/playground/#form-submit

sutherland left a reply on Problem With Laravel Collectiev • 6 months ago

Like I said before, that's exactly what two curly braces is supposed to do, you need the {!! !!} version if you want to contents to be HTML.

https://laravel.com/docs/5.1/blade#displaying-data

sutherland left a reply on Problem With Laravel Collectiev • 6 months ago

Two curly braces will HTML encode anything inside, this is good for displaying user input in case it contains any tags. Using the exclamantion point version will directly echo anything inside, which in your case you need so you can output the form HTML.

sutherland left a reply on Select Value Data Not Being Stored • 6 months ago

Here's my idea:

<script type="text/javascript">
  $(document).ready(function() {
    $('#programSelect').change(function() {
      $('.scopes').hide();
      $('.scopes select').removeAttr('name');
      $('#' + $(this).val()).show();
      $('#' + $(this).val() + ' select').attr("name", "scope_id");
    });
  });
</script>

Haven't used jQuery in awhile so I know it's not the most efficient way but it should get the job done.

sutherland left a reply on Select Value Data Not Being Stored • 6 months ago

It's because you have multiple <select> elements with the same name, and the last one (or it might be the first?) overrides all the other ones. Modify your jQuery to remove the name attribute from the hidden select fields and add the name field to the active one.

sutherland left a reply on How To Find Nearest Cities From Latitude And Longitude • 6 months ago

@murilo strange, I almost suggested that but in my config I had it set to true so I thought it wouldn't matter. I guess maybe I have that configured somewhere else...

sutherland left a reply on Using Trait On Observer • 6 months ago

If all the observers are going to have the same methods, why not just create a generic observer like ActivityObserver that uses the generic model class?

So instead of your ThreadObserver having something like this:

public function created(Thread $thread)
{
    //
}

You'd do something like this:

use Illuminate\Database\Eloquent\Model;

...

public function created(Model $model)
{
    //
}

Then the observer will be able to be registered for any model.

sutherland left a reply on MethodNotAllowedHttpException Error • 6 months ago

It's still submitting the form the old fashioned way, you need to prevent the default action like so:

<script>
        $('#loginForm').submit(function (e) {
            e.preventDefault();
            initLogin($('#email').val(),$('#password').val());
        });
</script>

sutherland left a reply on How To Preview Image Before Uploading. • 6 months ago

Check out this lesson: https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/65

It might be named AJAX image uploads but it also shows how you can use JavaScript to display a selected file before uploading.

Here's some more info with a jQuery example as well: https://stackoverflow.com/questions/24837646/onchange-file-input-change-img-src-and-change-image-color

sutherland left a reply on Auto Data Entry Into Desktop Application • 6 months ago

I think it's safe to assume it's not his desktop application, hence the reason he's looking for another way to import the data.

sutherland left a reply on How To Find Nearest Cities From Latitude And Longitude • 6 months ago

Yes, MySQL 5.7 and no issues here.

sutherland left a reply on Boolean Field Returns Empty When Set To False In Blade • 6 months ago

That's the way echoing a boolean as a string works. You should do the following:

var xxx = "{{ Auth::user()->alertConfigs->progress_bar ? '1' : '0' }}"

sutherland left a reply on Observer Is Not Firing. • 6 months ago

Are you sure you've imported ThreadObserver at the top of your AppServiceProvider and given it the correct namespace in ThreadObserver.php?

sutherland left a reply on How To Find Nearest Cities From Latitude And Longitude • 6 months ago

You don't need a distance column, the raw select statement is calculating it for you.

I just tested this on Laravel 5.6 with no issues:

$latitude = 25.000;
$longitude = 25.000;

$cities = City::selectRaw('*, ( 6367 * acos( cos( radians(' . $latitude . ') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(' . $longitude . ') ) + sin( radians(' . $latitude . ') ) * sin( radians( latitude ) ) ) ) AS distance')
    ->having('distance', '<', 30)
    ->orderBy('distance')
    ->get();

What database driver are you using?

sutherland left a reply on Why It Appears This Error: "Route [rtypes.update] Not Defined"? • 6 months ago

Can you show your update and store controller methods? I still think you need to update your 'rtypes.store' route like this:

Route::post('conference/update/{id}/rtypes', [ 'uses' => '[email protected]', 'as'=>'rtypes.update']);

Route::post('conference/store/{id}/rtypes', [ 'uses' => '[email protected]', 'as'=>'rtypes.store']);

You said when a user "stores a registration type it goes to a blank page" so it sounds like you just need to perform a redirect at the end of your store() method?

sutherland left a reply on Queue Worker Query With Locks • 6 months ago

I'd assume it's to avoid having multiple workers do something to the same job at the same time? Is it causing a problem?

sutherland left a reply on Why It Appears This Error: "Route [rtypes.update] Not Defined"? • 6 months ago

I don't understand what the code and data is exactly trying to accomplish, but if the view is the same and the controller is the same, why do you need two different actions for your form? Can you break down what exactly what the site is doing?

sutherland left a reply on Why It Appears This Error: "Route [rtypes.update] Not Defined"? • 6 months ago

You don't have to create another view, just a controller method that uses the same view.

sutherland left a reply on Why It Appears This Error: "Route [rtypes.update] Not Defined"? • 6 months ago

Ah, I see now. Both your routes (rtypes.store and rtypes.update) are using a POST request with the same URL, so it must only be registering one of them. Try changing the store URL to something like 'conference/store/{id}/rtypes'

sutherland left a reply on Why It Appears This Error: "Route [rtypes.update] Not Defined"? • 6 months ago

If you run php artisan route:list in your terminal do you see the rtypes.update route listed?

sutherland left a reply on How To Find Nearest Cities From Latitude And Longitude • 6 months ago

The raw query in the select is using AS to calculate the distance. I just copied it from an old Laravel 4 project so I'm not sure what's changed.

Maybe try changing ->having('distance', '<', 25) to ->where('distance', '<', 25)?

sutherland left a reply on How To Find Nearest Cities From Latitude And Longitude • 6 months ago

If you already have the latitude and longitudes in your database you might as well query them yourself. This is from a project where I'm doing something similar:

$cities = City::select(DB::raw('*, ( 6367 * acos( cos( radians('.$latitude.') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('.$longitude.') ) + sin( radians('.$latitude.') ) * sin( radians( latitude ) ) ) ) AS distance'))
    ->having('distance', '<', 25)
    ->orderBy('distance')
    ->get();

sutherland left a reply on Add IP To Contact Form • 6 months ago

That's because your IP column in your table doesn't allow null values. Contact::create() tries to insert the data without an IP defined yet and MySQL shows an error as it should. Here's what you can do:

    public function store(ContactRequest $request)
    {
        $contact = new Contact($request->all());

        $contact->ip = $request->ip();

        $contact->save();
    }

Now it's only executing the query once after everything has been filled.

sutherland left a reply on Checkbox Not Displaying A Tick • 6 months ago

Then define an accessor like this on your model:

    public function getDciAttribute($value)
    {
    if (is_null($value)) {
                return [];
        }

        return $value;
    }
Edit Your Profile
Update

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