Laravel check if collection is empty

To determine if there are any results you can do any of the following: if ($mentor->first()) { } if (!$mentor->isEmpty()) { } if ($mentor->count()) { } if (count($mentor)) { } if ($mentor->isNotEmpty()) { } Notes / References ->first() https://laravel.com/api/5.7/Illuminate/Database/Eloquent/Collection.html#method_first isEmpty() https://laravel.com/api/5.7/Illuminate/Database/Eloquent/Collection.html#method_isEmpty ->count() https://laravel.com/api/5.7/Illuminate/Database/Eloquent/Collection.html#method_count count($mentors) works because the Collection implements Countable and an internal count() method: … Read more

Where are logs located?

Ensure debug mode is on – either add APP_DEBUG=true to .env file or set an environment variable Log files are in storage/logs folder. laravel.log is the default filename. If there is a permission issue with the log folder, Laravel just halts. So if your endpoint generally works – permissions are not an issue. In case … Read more

Manually register a user in Laravel

I think you want to do this once-off, so there is no need for something fancy like creating an Artisan command etc. I would suggest to simply use php artisan tinker (great tool!) and add the following commands per user: $user = new App\Models\User(); $user->password = Hash::make(‘the-password-of-choice’); $user->email=”the-email@example.com”; $user->name=”My Name”; $user->save();

how to test specific test class using phpunit in laravel

After trying several ways, I found out that I don’t need to include the folder to test the specific test class. This works for me it runs all the test on the class: phpunit –filter ApplicationVersionFormatTest I think it’s because my ApplicationVersionFormatTest extend The TestCase and return application instance which serves as the “glue” for … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)