fredmarks

fredmarks

Member Since 3 Years Ago

Experience Points
1,050
Total
Experience

3,950 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
1
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
1,050 XP
Sep
24
1 month ago
Activity icon

Replied to Better Way To Validate An Optional, Nullable Field

I forgot to mention that I also already tried sometimes it did not work, because the field is always present (in the form) so its always part of the $_POST. Sometime works when the actual field may sometimes not be present at all in the post request

Activity icon

Started a new Conversation Better Way To Validate An Optional, Nullable Field

I have an optional form field, which, when it is filled, I want to check against the users table (if it exists)

This is working, but its verbose

            'account_manager' => [
                'nullable',
                function ($attribute, $value, $fail) {
                    if ($value != '') {
                        if (\App\Models\User::Where('id', $value)->doesntExist()) {
                            return $fail('User not found');
                        }
                    }
                },
            ],

This is cleaner but its checking the exist rule, even when no value has been passed

            'account_manager' => [
                'nullable',
                Rule::exists('users', 'id'),
            ],

is there a way to make the above, slimmer code work?

Aug
30
1 month ago
Activity icon

Replied to My Apps Web Installer - Session Problems

Finally got this to work. I was making a really silly error.

In my Setup middleware, i was using

Auth::logout();

instead of

\Auth::logout();

because I had not specifed

use Auth;
Activity icon

Replied to My Apps Web Installer - Session Problems

I have created a Middleware called Setup and have placed it before the system middle ware.


//Kernel.php

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [

            //setup
            \App\Http\Middleware\General\Setup::class,

            //system middleware
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            //[growcrm] [general middleware]
            \App\Http\Middleware\General\SanityCheck::class,
            //[growcrm] [general middleware]
            \App\Http\Middleware\General\General::class,
        ],

        'api' => [
            'throttle:60,1',
            'bindings',
        ],
    ];


//Setup middleware

    public function handle($request, Closure $next) {

        if (!env('SETUP_COMPLETED')) {
            Artisan::call('cache:clear');
            Artisan::call('route:clear');
            Artisan::call('config:clear');
            Session::flush();
            Cookie::forget('laravel_session');
            return $next($request);
        }

    }

Below is the stack trace

[2020-08-30 05:52:56] local.ERROR: SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from `users` where `id` = 1 limit 1) {"exception":"[object] (Illuminate\Database\QueryException(code: 2002): SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from `users` where `id` = 1 limit 1) at /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Database/Connection.php:671)
[stacktrace]
#0 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Database/Connection.php(631): Illuminate\Database\Connection->runQueryCallback('select * from `...', Array, Object(Closure))
#1 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Database/Connection.php(339): Illuminate\Database\Connection->run('select * from `...', Array, Object(Closure))
#2 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2202): Illuminate\Database\Connection->select('select * from `...', Array, true)
#3 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2190): Illuminate\Database\Query\Builder->runSelect()
#4 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2685): Illuminate\Database\Query\Builder->Illuminate\Database\Query\{closure}()
#5 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2191): Illuminate\Database\Query\Builder->onceWithColumns(Array, Object(Closure))
#6 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(539): Illuminate\Database\Query\Builder->get(Array)
#7 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(523): Illuminate\Database\Eloquent\Builder->getModels(Array)
#8 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(143): Illuminate\Database\Eloquent\Builder->get(Array)
#9 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php(68): Illuminate\Database\Eloquent\Builder->first()
#10 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php(177): Illuminate\Auth\EloquentUserProvider->retrieveByToken('1', 'elMHZK0L2lQSBJ8...')
#11 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php(147): Illuminate\Auth\SessionGuard->userFromRecaller(Object(Illuminate\Auth\Recaller))
#12 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Auth/GuardHelpers.php(60): Illuminate\Auth\SessionGuard->user()
#13 /var/www/html/mydomain.com/application/app/Http/Middleware/RedirectIfAuthenticated.php(20): Illuminate\Auth\SessionGuard->check()
#14 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\RedirectIfAuthenticated->handle(Object(Illuminate\Http\Request), Object(Closure))
#15 /var/www/html/mydomain.com/application/app/Http/Middleware/General/General.php(23): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#16 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\General\General->handle(Object(Illuminate\Http\Request), Object(Closure))
#17 /var/www/html/mydomain.com/application/app/Http/Middleware/General/SanityCheck.php(45): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#18 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\General\SanityCheck->handle(Object(Illuminate\Http\Request), Object(Closure))
#19 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#20 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#21 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(76): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#22 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#23 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#24 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#25 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#26 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(62): Illuminate\Session\Middleware\StartSession->handleStatefulRequest(Object(Illuminate\Http\Request), Object(Illuminate\Session\Store), Object(Closure))
#27 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#28 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#29 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#30 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(66): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#31 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#32 /var/www/html/mydomain.com/application/app/Http/Middleware/General/Setup.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#33 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\General\Setup->handle(Object(Illuminate\Http\Request), Object(Closure))
#34 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#35 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Routing/Router.php(687): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#36 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Routing/Router.php(662): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#37 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Routing/Router.php(628): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
#38 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Routing/Router.php(617): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#39 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(165): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#40 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#41 /var/www/html/mydomain.com/application/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(58): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#42 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle(Object(Illuminate\Http\Request), Object(Closure))
#43 /var/www/html/mydomain.com/application/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#44 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fideloper\Proxy\TrustProxies->handle(Object(Illuminate\Http\Request), Object(Closure))
#45 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#46 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#47 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#48 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#49 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#50 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))
#51 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(63): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#52 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#53 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#54 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(140): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#55 /var/www/html/mydomain.com/application/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(109): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#56 /var/www/html/mydomain.com/index.php(69): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#57 {main}

The stack trace shows that

  • #32 /Http/Middleware/General/Setup.php is being executed before
  • #26 Illuminate/Session/Middleware/StartSession.php
Activity icon

Replied to My Apps Web Installer - Session Problems

It looks like this is all happening while the app is bootstraping, so there is no way for me to remove the cookie before the check has been done. I have tried placing this code in all sorts of places, but the check will have already have been done.

I am trying to avoid changing core laravel files

Aug
29
1 month ago
Activity icon

Replied to My Apps Web Installer - Session Problems

Yes, the wizard I created will do the usual things like check for server requirements, folder permissions etc. I will then seed the database and update/write the .env file.

It's working very well, apart from this edge case scenario, where a user might want to reinstall on the same domain name than the run into this session issue

Activity icon

Replied to My Apps Web Installer - Session Problems

It certainly a cookie thing, because if I open a different browser, on the same computer, the installer starts just fine.

Activity icon

Replied to My Apps Web Installer - Session Problems

I have done all this, further more, I have physically deleted all the contents of the cache folder.

I have also added Auth::logout();

Activity icon

Started a new Conversation My Apps Web Installer - Session Problems

I have created an application that comes with a web installer(e.g. like the Wordpress one).

  • The web installers asks for database details, etc
  • it then dynamically writes this information to the .env file.
  • The user then completes installation and they can log in and start using the app.

Here is the problem

Whilst testing, if I complete installing the application, login and use it for a while and then decide to do a new installation (same domain name, testing over and over), laravel is trying to connect to the database to authenticate the previous user (even though the .env file is clean and has no database information and has session driver set to 'file')

  • I have cleared all cache in laravel

If I clear my browser cache, the web installer works as expected, the user is able to set database information etc, which the installer then writes to the .env file and changes the session driver to database.

Even though I have cleared all the laravel cache files, what I think is happening is that the new installation is picking up on the browser cookie from the last time it was installed.

Log files show a timeout trying to connect to the database (which has not been set yet)

SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from `users` where `id` = 1 limit 1) {"exception":"[object] (Illuminate\Database\QueryException(code: 2002): SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from `users` where `id` = 1 limit 1) 

I hope I have explained it correctly

I have tried various things, including

//I have this in my web installers controller __construct()

$this->middleware('guest');

//inside my AppServiveProvider.php

//trying to delete any previous sessions, if installer has not completed
if (!env('SETUP_COMPLETED') ) {
       Auth::logout();
       \Session::flush();
}

none of this is working

Looking at the stack trace from the error log, I can see that it's the remember me cookie that the SessionGuard* is pulling up and trying to recreate the old session.

How can I fix this?

Apr
25
6 months ago
Activity icon

Replied to How To Get Carbon To Return Only A Future Date

Thank you all for the help

Activity icon

Replied to How To Get Carbon To Return Only A Future Date

@michaloravec Thanks for the reply

I need the new future date to fall on same day as it would have been, had the cycle not been paused

i.e. 2020-01-23 should become 2020-05-23

If I used now() I will end up with 2020-05-25 (e.g. based on todays date 25th April)

Activity icon

Started a new Conversation How To Get Carbon To Return Only A Future Date

I am working on recurring invoices, that recur every month.

I have a parent invoice which is used to generate new child invoices every month.

In the parent invoice, I keep track of the last recurring cycle date using a field last_renewed

This sounds simple enough to just use ->addMonth() on last_renewed to determin the next renewal date

HOWEVER

I also have a feature to allow pausing of the recurring cycle. Now, if the recurring is resumed after some months have passed, how can I get carbon to return a sure future next cycle date, based off the last_renewed date (which could now be, 4 months ago (e.g. 25 January 2020))

Using addMonth() or modify('next month') on last_renewed date, will return 25 February 2020. What i really want is 25 May 2020