1👍
Assuming you set up the relationship between Permit and State models, and you want to count the number of permits for each state (so I think you meant to have a 1:N relation), you could do like this:
$data = State::withCount('permits')->all();
// Then when you need to extract data
$chart = new PermitsChart;
$chart->labels($data->pluck('name'));
// To retrive the permit_count foreach state you can to
$data->pluck('permits_count'); // Array of counts
Update
To set up relationships between your model you have to add:
Permit.php
class Permit extends Model
{
// Your existing code
public function state()
{
return $this->belongsTo(State::class);
}
}
State.php
class State extends Model
{
// Your existing code
public function permits()
{
return $this->hasMany(Permit::class);
}
}
Source:stackexchange.com