garrettmassey

Member Since 11 Months Ago

Experience Points
5,160
Total
Experience

4,840 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
48
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.

  • Community Pillar

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

Level 2
5,160 XP
May
12
2 days ago
Activity icon

Awarded Best Reply on Getting Count Of Records Between Two Dates Returning 0

For some reason, when I test it by adding dd($q3); in the local scope function, it returns 0, but if I dump the count in my controller it returns the proper count. I am not sure why, but the code I posted does work.

Activity icon

Replied to Getting Count Of Records Between Two Dates Returning 0

For some reason, when I test it by adding dd($q3); in the local scope function, it returns 0, but if I dump the count in my controller it returns the proper count. I am not sure why, but the code I posted does work.

Activity icon

Started a new Conversation Getting Count Of Records Between Two Dates Returning 0

I am setting up a local scope in one of my models so that when you access it, it returns the count of records for a specific fiscal quarter. The scope is set up below:

public function scopeAllQuarterCount($query)
{

	$now = Carbon::now();

	$year = Carbon::now()->year;

	$fy_start = new Carbon('first day of July ' . $year);

	if($now < $fy_start) {
		$ys = $year - 1;
		$ye = $year;
		$current_fy = "" . $ys . " - " . $ye;

		$q3 = $query->whereBetween('created_at', 
			[
				(Carbon::parse("January 1, " . $ye)->format('Y-m-d h:i:s')), 
				(Carbon::parse("March 31, " . $ye)->format('Y-m-d h:i:s'))
			])->count();

		return $q3;

	}

	else {
		//tbd
	}
}

Our fiscal year starts on July 1, so I have a small check to see if we are in the new fiscal year or not (if the date is past July 1 of the current year). Then, for Q3, which starts on Jan 1 and ends on Mar 31, I get the count of all records between those dates of the current fiscal year. It should return a count of ~1400 but I am getting 0.

May
04
1 week ago
Activity icon

Awarded Best Reply on HasManyThrough Relationship Returning Empty Array

So, I realized after migrating my code to a new repository, I didn't run the database migrations. The code was actually working, but because I hadn't run the migrations there wasn't any data to show, hence the empty array and 0 count. Running the migrations worked, and I completely forgot to check that when I moved to the new repository.

Thank you for your help!

Activity icon

Replied to HasManyThrough Relationship Returning Empty Array

So, I realized after migrating my code to a new repository, I didn't run the database migrations. The code was actually working, but because I hadn't run the migrations there wasn't any data to show, hence the empty array and 0 count. Running the migrations worked, and I completely forgot to check that when I moved to the new repository.

Thank you for your help!

Activity icon

Replied to HasManyThrough Relationship Returning Empty Array

Unfortunately all configurations of the foreign key orders either returns a foreign-key-constraint error or it "works" but the array is still empty, or the count is still 0.

I'm stumped so far.

May
03
1 week ago
Activity icon

Replied to HasManyThrough Relationship Returning Empty Array

Sorry for the late reply,

when I add ->get() it still returns an empty set / collection.

Apr
30
2 weeks ago
Activity icon

Started a new Conversation HasManyThrough Relationship Returning Empty Array

Hello!

I have a database that has several tables, but we only need to focus on 3:

providers

  • id
  • name
  • status
  • type_of_care_id

caretype

  • id
  • name
  • category

category

  • id
  • name

A provider can have 1 care type, and multiple care types can belong to 1 category.

I have a HasManyThrough relationship set up in my CareCategory controller, but it returns an empty array, and I'm not quite sure why:

class CareType extends Model
{
    public function providers() {
        return $this->hasMany('App\Models\Providers', 'type_of_care_id');
    }

    public function category() {
        return $this->belongsTo('App\Models\CareCategory', 'category');
    }
}


class CareCategory extends Model
{
    public function care_type() {
        return $this->hasMany('App\Models\CareType', 'category');
    }

    public function providers()
    {
        return $this->hasManyThrough('App\Models\Provider', 'App\Models\CareType', 'category', 'type_of_care_id', 'id', 'id');
    }
}


class Provider extends Model
{
    public function caretype() {
        return $this->belongsTo('App\Models\CareType', 'type_of_care_id');
    }
}

When I try to get the providers in a specific category like this: $cat_pro = CareCategory::find($id)->providers(); it returns an empty array, even though I know there are providers in that category.

Any help would be greatly appreciated!

Feb
03
3 months ago
Activity icon

Replied to Laravel 6.2.11 Validation Rules Not Working Sitewide

Oh my gosh thank you for your help.

It turns out that in app/http/kernel.php I had added a middleware for StartSession in the protected group:

protected $middleware = [
    \App\Http\Middleware\TrustProxies::class,
    \App\Http\Middleware\CheckForMaintenanceMode::class,
    \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
    \App\Http\Middleware\TrimStrings::class,
    \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
    //\Illuminate\Session\Middleware\StartSession::class
];

Commenting out that one line fixed every issue with the validation errors, and I don't see any issues with the rest of the app so far after commenting it out. Also, the original Laravel 6.0 kernel.php doesn't have the line \Illuminate\Session\Middleware\StartSession::class in that protected array, so I must have added it to the group some time ago and forgotten.

Thank you for troubleshooting so much with me.

Activity icon

Replied to Laravel 6.2.11 Validation Rules Not Working Sitewide

Using put instead of flash worked, and the session message appeared correctly.

Activity icon

Replied to Laravel 6.2.11 Validation Rules Not Working Sitewide

I have disabled both of the custom middlewares at this point.

I think something is not working with the session. I tried to see if I could flash any message to the session by adding:

public function store(Request $request)
{
    
    Session::flash('message', 'Task was successful!');
    return redirect()->route('create_providers');
}

where create_providers is the route name of the form being submitted. Then in the blade template, I added this:

@if(Session::has('message'))
    {{ Session::get('message') }}
@endif

to the card title so it would be easy to see. On submit and on refresh nothing changes and no messages are displayed.

Edit: But if I just dd(Session::all()); I get an array of five values:

array:5 [▼
  "_token" => "<<intentionally removed by me>>"
  "_flash" => array:2 [▶]
  "login_web_<<key>>" => 1
  "_previous" => array:1 [▶]
  "password_hash" => "<<intentionally removed by me>>"
]
Activity icon

Replied to Laravel 6.2.11 Validation Rules Not Working Sitewide

I added the following code to the blade template to see if any errors were being flashed at all and there was no change:

@php
  if($errors->any()) {
    dd($errors);  
  }
@endphp

I also just tried to dd($errors); without the conditional, and it returns an empty "bag". To simplify and see if it was an issue with the validation rules, I also changed the validation rules to just:

$validatedData = $request->validate([
        'inputProvider' => ['required'],
 ]);

And the issue persisted.

Activity icon

Replied to Laravel 6.2.11 Validation Rules Not Working Sitewide

Commenting out the \App\Http\Middleware\HttpsProtocolMiddleware::class, doesn't seem to have any effect, unfortunately.

Activity icon

Replied to Laravel 6.2.11 Validation Rules Not Working Sitewide

The only other thing I have done to change the web middleware is add a new class to the web middleware group in app/http/kernal.php:

protected $middlewareGroups = [
    'web' => [
        \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,
        \App\Http\Middleware\HttpsProtocolMiddleware::class,
        \App\Http\Middleware\SetUUIDCookie::class,
    ],

where the HttpsProtocolMiddleware is:

public function handle($request, Closure $next)
{
    if (!$request->secure() && app()->environment('production')) {
        return redirect()->secure($request->getRequestUri());
    }

    return $next($request);
}

and the SetUUIDCookie is:

public function handle($request, Closure $next)
{
    
    if($request->hasCookie('uid')) {
        return $next($request);    
    }

    $uuid = Str::uuid()->toString();
    $response = $next($request);
    return $response->withCookie(cookie('uid', $uuid, 60));
    //return $next($request);
}
Activity icon

Replied to Laravel 6.2.11 Validation Rules Not Working Sitewide

The routes for the majority of the application are in a protected group: Route::middleware('auth')->group(function () {, would that possibly be the cause? Even though it's a different middleware?

Edit: I moved the routes out of the middleware group in the routes/web.php and the issue of the errors not showing up still happens.

Activity icon

Started a new Conversation Laravel 6.2.11 Validation Rules Not Working Sitewide

Laravel 6.2.11 validation rules seem to not be working sitewide on our project.

Controller:

<?php

namespace App\Http\Controllers;

use App\Models\Provider;
use Illuminate\Http\Request;
use Ixudra\Curl\Facades\Curl;
use Illuminate\Support\Facades\DB;

class ProviderController extends Controller
{
    
    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {


         $validatedData = $request->validate([
                        'inputProvider' =>'required|unique:providers,business_name',
                        'type' =>'required',
                        'latitude' =>'required',
                        'longitude' =>'required',
                        'inputWebsite' =>'required',
                        'status' =>'required',
         ]);
         $user = auth()->user();

         $typeId = $request->get('type');
         $statusId = $request->get('status');
         $data = new Provider();
         $data->business_name = $request->inputProvider;
         $data->type_of_care_id =$typeId ;
         $data->lat = $request->latitude;
         $data->long = $request->longitude;
         $data->website = $request->inputWebsite;
         $data->status_id =$statusId ;
         $data->created_by=$user->id;
         $data->save();
         return redirect()->route('list_providers');
    }

Form:

    <div class="row">
    <div class="col-md-11">
        <div class="card card-border-0 card-border-color-0">
            <div class="card-header card-header-Bootstrap">Add Provider</div>
            <div class="card-body">
                @if ($errors->any())
                    <div class="alert alert-danger">
                        <ul>
                            @foreach ($errors->all() as $message)
                            <li>{{ $message }}</li>
                            @endforeach
                        </ul>
                    </div>
                @endif
                <form action="/dashboard/providers/store"  method = "POST">
                    @csrf
                    
                    <div class="card-divider"></div>
                    <div class="form-group row">
                        <label class="col-12 col-sm-3 col-form-label text-sm-right">Provider</label>
                        <div class="col-12 col-sm-8 col-lg-6">
                            <div class="input-group input-group-lg mb-3">
                                <input class="form-control" type="text" name="inputProvider" id="inputProvider" placeholder="Enter the Provider">
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-12 col-sm-3 col-form-label text-sm-right">Care Type</label>
                        <div class="col-12 col-sm-8 col-lg-6">
                            <select class="browser-default custom-select" name="type" >
                                <option></option>
                                @foreach($careType as $item)
                                <option value="{{ $item->id}}">{{ $item->type}}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-12 col-sm-3 col-form-label text-sm-right">Location/City/Address </label>
                        <div class="col-12 col-sm-8 col-lg-6">
                            <div class="input-group input-group-lg mb-3">
                                <input type="text" name="autocomplete" id="autocomplete" class="form-control" placeholder="Select Location" onFocus="geolocate()">
                            </div>
                        </div>
                    </div>
                    <div class="form-group row" id="lat_area">
                        <label class="col-12 col-sm-3 col-form-label text-sm-right">Latitude</label>
                        <div class="col-12 col-sm-8 col-lg-6">
                            <div class="input-group input-group-lg mb-3">
                                <input type="text" name="latitude" id="latitude" class="form-control" placeholder="Enter the Latitude" readonly>
                            </div>
                        </div>
                    </div>
                    <div class="form-group row" id="long_area">
                        <label class="col-12 col-sm-3 col-form-label text-sm-right">Longitudes</label>
                        <div class="col-12 col-sm-8 col-lg-6">
                            <div class="input-group input-group-lg mb-3">
                                <input type="text" name="longitude" id="longitude" class="form-control" placeholder="Enter the Longitude" readonly>
                            </div>
                        </div>
                    </div>
                    <div class="form-group row" id="ctry">
                        <label class="col-12 col-sm-3 col-form-label text-sm-right">Country</label>
                        <div class="col-12 col-sm-8 col-lg-6">
                            <div class="input-group input-group-lg mb-3">
                                <input class="form-control" type="text" name="country" id="country" placeholder="Enter the Country" readonly >
                            </div>
                        </div>
                    </div>
                    <div class="form-group row" id="cty">
                        <label class="col-12 col-sm-3 col-form-label text-sm-right">County</label>
                        <div class="col-12 col-sm-8 col-lg-6">
                            <div class="input-group input-group-lg mb-3">
                                <input class="form-control" type="text" name="county" id="administrative_area_level_2" placeholder="Enter the County" readonly >
                            </div>
                        </div>
                    </div>
                    <div class="form-group row" id ="zip">
                        <label class="col-12 col-sm-3 col-form-label text-sm-right">Zip Code</label>
                        <div class="col-12 col-sm-8 col-lg-6">
                            <div class="input-group input-group-lg mb-3">
                                <input class="form-control" type="text" name="postal_code" id="postal_code" placeholder="Enter the Zip code" readonly >
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-12 col-sm-3 col-form-label text-sm-right">Website</label>
                        <div class="col-12 col-sm-8 col-lg-6">
                            <div class="input-group input-group-lg mb-3">
                                <input class="form-control" type="text" name="inputWebsite" id="inputWebsite" placeholder="Enter the Website">
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-12 col-sm-3 col-form-label text-sm-right">Provider Status</label>
                        <div class="col-12 col-sm-8 col-lg-6">
                            <select class="browser-default custom-select" name="status" >
                                <option></option>
                                @foreach($status as $item)
                                <option value="{{ $item->id}}">{{ $item->data}}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <p class="text-right">
                            <button class="btn btn-space btn-primary" type="submit">Submit</button>
                        </p>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

Nothing I have tried seems to get the validation to work. When you submit the form, if all of the requirements are met, the data is successfully inserted into the database, but if your request does not meet the validation requirements, the page refreshes without any error messages or displays, and the data is NOT submitted to the database. So the validation is working, but it's not displaying any errors.

What could be causing this? I thought it might have to do with publishing the custom error pages (404, 419, 500, etc) but that doesn't seem to be the issue. I have also tried using dd() to dump the validation, and to dump the request, but that doesn't reveal anything either.

EDIT:

I am running PHP 7.2.33 if that is needed.

Any help would be greatly appreciated!