sutherland

Experience

72,700

51 Best Reply Awards

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

24th September, 2017

sutherland left a reply on Sending Mails • 16 hours ago

You can use a service like Mailgun or Amazon's SES.

sutherland left a reply on Creating Base Selector For Model Queries • 17 hours ago

I think you can do $query = Game::query(); before you start adding conditions and just chain off of that. I'd also check out this lesson if you're going to be handling a lot of parameters.

23rd September, 2017

sutherland left a reply on Axios Wrong Response On Post • 1 day ago

I think it's polite to go ahead and provide what you learned was the problem while it's fresh on your mind, future searchers will thank you.

sutherland left a reply on How Do I Execute A Vue Click Event On Appended String? • 1 day ago

Try something like this: https://jsfiddle.net/50wL7mdz/63949/

Instead of inserting the elements yourself, create an array of items and a loop through them. Then you can call a method that receives the array item as an argument.

22nd September, 2017

sutherland left a reply on Eloquent Casts Array Returns Null Instead Of Empty Array • 2 days ago

You can check out the source yourself and see how casts work with the castAttribute() method.

You could use a trait, or it sounds like you may want to extend Illuminate\Database\Eloquent\Model with your own Model class. It would just need to override castAttribute(). Probably something like this:

namespace App;

use Illuminate\Database\Eloquent\Model as EloquentModel;

abstract class Model extends EloquentModel
{
    /**
     * Cast an attribute to a native PHP type.
     *
     * @param  string  $key
     * @param  mixed  $value
     * @return mixed
     */
    protected function castAttribute($key, $value)
    {
        if ($this->getCastType($key) == 'array' && is_null($value)) {
            return [];
        }

        return parent::castAttribute($key, $value);
    }
}

sutherland left a reply on Laravel Xsrf Token Validation After Login Expiration • 2 days ago

I would recommend catching the TokenMismatchException in your exception handler so you can redirect the user somewhere with an alert that their session has expired.

sutherland left a reply on Eloquent Casts Array Returns Null Instead Of Empty Array • 2 days ago

Casts will always return a null value as null, so what I'd recommend doing is setting up a custom accessor like so:

    public function getParamsAttribute($value)
    {
        if (is_null($value)) {
                $value = [];
        }

        return $value;
    }

sutherland left a reply on Axios Wrong Response On Post • 3 days ago

In chrome developer tools there is a "Network" tab you can look at to see the requests made on a page and view their responses. From there (or from your app's logs) you should be able to find out more about the error.

sutherland left a reply on Urgent Whoops • 3 days ago

In your .env file be sure you have APP_DEBUG=false. Should also set APP_ENV=production as well.

21st September, 2017

sutherland left a reply on Undefined Variable • 3 days ago

@zaster if you're posting code, you need to put three backticks on the line before and after the code.

sutherland left a reply on Start And Stop Queue • 3 days ago

If you leave the queue worker running it should process all the jobs and then just wait for new ones. If you're getting an error it's likely there's a problem with your job. Can you provide some code to look at? The job you use to schedule daily jobs and then the job that those execute?

sutherland left a reply on 5.5 Route::view With Language Data • 3 days ago

Glad to help, don't forget to mark your question as solved.

sutherland left a reply on Valet Runs Index.php Twice • 3 days ago

if you run valet which in the directory do you get this?

This site is served by [BasicValetDriver].

I didn't have a problem following these steps:

  1. Created a 'sample' directory in my sites folder.
  2. Created an index.php file which only runs exec('touch ' . rand(1,100));
  3. Accessed 'sample.dev'
  4. Checked folder, only see one random new file each time I refresh

sutherland left a reply on Accessing Parameters On Middleware • 3 days ago

It works for me. Here is my middleware:

namespace App\Http\Middleware;

use Closure;

class TestMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next, ...$params)
    {
        dd($params);

        return $next($request);
    }
}

And a test route:

Route::get('test', function() { return "hello world"; })->middleware('test:one,two,three');

sutherland left a reply on Accessing Parameters On Middleware • 3 days ago

According to the docs I believe you're doing it correctly.

Are you always expecting two arguments or can it be any number?

sutherland left a reply on Accessing Parameters On Middleware • 3 days ago

You can accept any number of parameters like so:

    public function handle($request, Closure $next, ...$params)
    {
        dd($params);

        return $next($request);
    }

sutherland left a reply on Vue JS Progress Bar • 3 days ago

Without knowing more details it's hard to help. How are you doing the processing? Is there a way you could make an endpoint that would return a percentage for a given process ID? You could make a script hit the endpoint once every 5 seconds or so. You could also look into broadcasting: https://laravel.com/docs/5.5/broadcasting

sutherland left a reply on Logout Issue After Uploading To Live Server • 3 days ago

You can run the command php artisan --version on your server to check. If you are manually uploading files using FTP, your composer.json and composer.lock may be out of sync.

sutherland left a reply on Logout Issue After Uploading To Live Server • 3 days ago

I'm sorry, I just remembered you're on 5.2, which I believe may have been using a get request. Was your production version using a more recent version of Laravel?

sutherland left a reply on Is Vue Js Best Pair With Laravel? • 3 days ago

There's nothing special about Vue and Laravel together, in fact in Laravel 5.5 there's a preset command to swap between none, bootstrap, vue, and react.

php artisan preset <type>

I personally use Vue because I found it had a lower learning curve, and because it's covered here extensively you'll be able to find a lot of help.

sutherland left a reply on Logout Issue After Uploading To Live Server • 3 days ago

So since it requires a post request, you need perform a logout like so:

<a href="{{ route('logout') }}"
    onclick="event.preventDefault();
             document.getElementById('logout-form').submit();">
    Logout
</a>

<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
    {{ csrf_field() }}
</form>

The real question is why it is working without this on your local environment.

sutherland left a reply on Logout Issue After Uploading To Live Server • 3 days ago

Surely your routes file has some reference to it, possibly Auth::routes(); which does in fact register it as a post request.

sutherland left a reply on Cannot Declare Class Because The Name Is Already In Use Error After Uploading To Server • 3 days ago

Because your Controller name is Departments you can't import App\Departments without aliasing it.

use App\Departments as DerpartmentsModel;

Then change your controller methods to use DepartmentsModel instead.

But, I think you really should just name the controller DepartmentsController to avoid this headache.

sutherland left a reply on Logout Issue After Uploading To Live Server • 3 days ago

Is your logout route configured to use a get request? It should really be a post request which is why in the example I gave it (from some Laravel boilerplate) had a hidden form that sends a POST request.

sutherland left a reply on Logout Issue After Uploading To Live Server • 3 days ago

Use three backticks on the line before and after a code block to format it.

sutherland left a reply on Logout Issue After Uploading To Live Server • 3 days ago

Again, in you view file, what does the logout link that you click to log out look like? Possibly something like this:

<a href="{{ route('logout') }}"
    onclick="event.preventDefault();
             document.getElementById('logout-form').submit();">
    Logout
</a>

<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
    {{ csrf_field() }}
</form>

sutherland left a reply on Logout Issue After Uploading To Live Server • 3 days ago

What does the logout link in your view look like?

sutherland left a reply on How Do I Pass A Variable Of Data From One File To Another File? • 3 days ago

Do you mean the same between page loads? Or the same between components?

sutherland left a reply on Logout Issue After Uploading To Live Server • 3 days ago

What does the logout link in your view look like? And is it actually logging you out, just redirecting to the wrong place, or is it leaving you logged in when you go to another real page?

sutherland left a reply on Custom 'Auth' Controller • 3 days ago

This example may be outdated but it should help: https://github.com/typetokrish/Laravel-Custom-Hashing

Obviously you'll still need to change the use of bcrypt() in the RegisterController's create method.

sutherland left a reply on Custom 'Auth' Controller • 3 days ago

For checking your existing password hashes, writing a custom user provider should do the trick.

As for writing extra columns during registration, the included app/Http/Controllers/Auth/RegisterController.php has a validator and create method you can just modify in place to add the extra fields you need and to hash the password using your own method.

I don't think you'll have too much trouble. The only thing I don't have experience with is customizing the session driver, but once getting a feel of how Laravel does things I'm sure you can get it going.

sutherland left a reply on When A Mail Is Not Sent How To Not Stop The Function? • 3 days ago

If it's important that the email be sent eventually, queueing is a much better option. Try/catch is just sweeping it under the rug unless you're using it to execute some logic like notifying the customer on the receipt page there was a problem sending the email.

sutherland left a reply on Custom 'Auth' Controller • 3 days ago

One of my Laravel sites came over from a WordPress site with many users, so I created a custom UserProvider that extends the default one and only overrides the validateCredentials() method to check if the password saved for the user was hashed using WordPress so it can check if the password is correct using that algorithm instead.

The controllers in app/Http/Controller/Auth/ are there for you to modify. I wouldn't write something totally new but instead look at the traits they use and override anything you need.

sutherland left a reply on Load Correct Environment • 3 days ago

Oops, didn't realize it was Lumen. It might not be something included in Lumen, a quick search of the Lumen source I don't see the same function Laravel uses to load .env.*** files.

sutherland left a reply on Load Correct Environment • 3 days ago

Maybe your config is cached? php artisan config:clear

sutherland left a reply on How To Include A Column In Select Query But Not Display It In Result • 3 days ago

It really concerns me that someone asking this question is storing SSNs.

sutherland left a reply on How To Add To Auth Middleware To /admin/anything ? • 3 days ago

Where you place your middleware is just preference. I usually include it in my routes just because it makes more sense to me to glance at routes and see it, but there are always exceptions.

It should actually be less repetitive using groups since you're not specifying the prefix and middleware each time?

Route::group(['prefix' => 'admin',  'middleware' => 'auth'], function()
{
    Route::get('/', function() {} );

    Route::get('dashboard', function() {} );

    Route::get('post', function() {} );
    Route::get('post/create', function() {} );
    Route::get('post/{post}/edit', function() {} );
    ...

    Route::get('user', function() {} );
    Route::get('user/create', function() {} );
    Route::post('user', function() {} );
    Route::get('user/{user}/edit', function() {} );
    ...

});

vs

Route::get('admin', function() {} )->middleware('auth');

Route::get('admin/dashboard', function() {} )->middleware('auth');

Route::get('admin/post', function() {} )->middleware('auth');
Route::get('admin/post/create', function() {} )->middleware('auth');
Route::get('admin/post/{post}/edit', function() {} )->middleware('auth');
...

Route::get('admin/user', function() {} )->middleware('auth');
Route::get('admin/user/create', function() {} )->middleware('auth');
Route::post('admin/user', function() {} )->middleware('auth');
Route::get('admin/user/{user}/edit', function() {} )->middleware('auth');
...

sutherland left a reply on Can't Access Variable From Controller In The Blade View • 3 days ago

You need to provide a name for the variable:

return View::make('my-test')->with('var', $var);

sutherland left a reply on How To Add To Auth Middleware To /admin/anything ? • 3 days ago

You'd need all the routes that start with /admin/ placed in the group.

Route::group(['prefix' => 'admin',  'middleware' => 'auth'], function()
{
    Route::get('/', function() {} );

    Route::get('post', function() {} );

    Route::get('dashboard', function() {} );
});

sutherland left a reply on API Advice Required Please. • 3 days ago

You may be overthinking it a bit, but I believe each user just needs a role, then you can write policies for each model to check if the user has the correct role and is authorized to perform an action. You'd be able to reuse your policies throughout your app.

https://laravel.com/docs/5.5/authorization#creating-policies

sutherland left a reply on When A Mail Is Not Sent How To Not Stop The Function? • 3 days ago

Use a queue to send the email: https://laravel.com/docs/5.5/mail#queueing-mail

You'll need to be sure you have your queue configured correctly and a queue worker running, but it should be the solution to your problem. It even will retry a queued job if it fails the first time.

sutherland left a reply on How To Add To Auth Middleware To /admin/anything ? • 3 days ago

Use a route group prefix, and apply the middleware to the group and all child routes will use it as well: https://laravel.com/docs/5.5/routing#route-group-prefixes

sutherland left a reply on Auto Registration By Php Laravel • 3 days ago

Glad to help, don't forget to mark your question solved

sutherland left a reply on How To Best Use A Pivot As A Model? • 3 days ago

@SwissNight if you look at the source of the Illuminate\Database\Eloquent\Relations\Pivot class you'll see it is extending Illuminate\Database\Eloquent\Model, so I assume the Pivot model would allow the same methods.

sutherland left a reply on Accessing Props From A Method • 3 days ago

Have you tried using another name for the prop? It could be that component is a reserved name.

sutherland left a reply on Middleware('auth:api') Redirect /home • 3 days ago

Glad it worked out, please mark your question solved.

sutherland left a reply on Lavavel Get Posts Of Last Month. • 3 days ago

$posts = Post::orderBy('desc')
    ->whereDate('created_at', \Carbon\Carbon::now()->subWeek())
    ->get();

$posts = Post::orderBy('desc')
    ->whereDate('created_at', \Carbon\Carbon::now()->subMonth())
    ->get();

sutherland left a reply on Laravel Validator Rules In Array • 3 days ago

Just use a double quote:

$validator = Validator::make($request->all(), [
    'password' => [
        'required',
        "min:$min"
    ]
]);

sutherland left a reply on Route::resource Error • 3 days ago

What does php artisan route:list show? It sounds like the show route is being registered before the create route, which means it ends up trying to use /bigilendirme/duyuru/{id} while passing 'create' as the id.

Edit Your Profile
Update

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