我正在尝试在 admin.dashboard 上添加一个组件,并且我也在 DashboardController 中定义了变量,但是它在前端也显示变量未定义。我已附加...
我正在尝试在 admin.dashboard 上添加一个组件,并且我也在 DashboardController 中定义了变量,但是它在前端显示变量未定义。
我已附上 DashboardController 和 Dashboard.Blade.php 的代码
class DashboardController extends Controller
{
public function index()
{
$currentMonth = Carbon::now()->month;
$selectedCount = Form::where('status', 'Selected')->whereMonth('created_at', $currentMonth)->count();
$notSelectedCount = Form::where('status', 'Not Selected')->whereMonth('created_at', $currentMonth)->count();
$holdCount = Form::where('status', 'Hold')->whereMonth('created_at', $currentMonth)->count();
// Prepare data for the graph
$monthlyData = Form::selectRaw('YEAR(created_at) as year, MONTH(created_at) as month, status, COUNT(*) as count')
->groupBy('year', 'month', 'status')
->get()
->groupBy(['year', 'month', 'status']);
return view('admin.dashboard', compact('currentMonth', 'holdCount', 'selectedCount', 'notSelectedCount', 'monthlyData'));
}
}
我还附上了dashboard.blade.php的代码
<!-- Rectangles showing counts -->
<div class="grid grid-cols-3 gap-4 my-8">
<div class="bg-green-500 text-white p-4 rounded-lg shadow-lg">
<h4 class="text-2xl">Selected</h4>
<p class="text-3xl">{{ $selectedCount }}</p>
</div>
<div class="bg-red-500 text-white p-4 rounded-lg shadow-lg">
<h4 class="text-2xl">Not Selected</h4>
<p class="text-3xl">{{ $notSelectedCount }}</p>
</div>
<div class="bg-yellow-500 text-white p-4 rounded-lg shadow-lg">
<h4 class="text-2xl">Hold</h4>
<p class="text-3xl">{{ $holdCount }}</p>
</div>
</div>
<!-- Graph showing monthly data -->
<div>
<canvas id="interviewChart"></canvas>
</div>
</div>
</main>
</div>
@push('scripts')
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
const ctx = document.getElementById('interviewChart').getContext('2d');
const monthlyData = @json($monthlyData);
const labels = [];
const selectedCounts = [];
const notSelectedCounts = [];
const holdCounts = [];
Object.keys(monthlyData).forEach(year => {
Object.keys(monthlyData[year]).forEach(month => {
labels.push(`${year}-${month}`);
selectedCounts.push(monthlyData[year][month]['Selected'] ? monthlyData[year][month]['Selected'][0].count : 0);
notSelectedCounts.push(monthlyData[year][month]['Not Selected'] ? monthlyData[year][month]['Not Selected'][0].count : 0);
holdCounts.push(monthlyData[year][month]['Hold'] ? monthlyData[year][month]['Hold'][0].count : 0);
});
});
new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [
{
label: 'Selected',
data: selectedCounts,
borderColor: 'green',
fill: false
},
{
label: 'Not Selected',
data: notSelectedCounts,
borderColor: 'red',
fill: false
},
{
label: 'Hold',
data: holdCounts,
borderColor: 'yellow',
fill: false
}
]
},
options: {
responsive: true,
scales: {
x: {
type: 'time',
time: {
unit: 'month'
}
}
}
}
});
});
</script>
@endpush
表格迁移代码
public function up()
{
Schema::create('forms', function (Blueprint $table) {
$table->id();
$table->date('interviewdate');
$table->date('dateofbirth');
$table->string('fullname');
$table->string('email')->unique();
$table->string('contactno')->unique();
$table->string('alternateno')->nullable();
$table->string('address');
$table->string('location')->nullable();
$table->string('pincode');
$table->string('experience_status')->default('Not Specified')->change();
//$table->string('experience_status');
$table->string('aadharno')->unique()->nullable();
$table->string('applydesign')->nullable();
$table->string('process')->nullable();
$table->string('interviewtaken')->nullable();
$table->string('otherTextbox')->nullable();
$table->string('statusbyhr')->nullable();
$table->string('secinterviewtaken')->nullable();
$table->string('status')->nullable();
$table->date('dateofjoining')->nullable();
$table->string('document')->nullable();
$table->text('documentDetails')->nullable();
$table->string('document2')->nullable();
$table->text('document2Details')->nullable();
$table->string('document3')->nullable();
$table->text('document3Details')->nullable();
$table->string('document4')->nullable();
$table->text('document4Details')->nullable();
$table->string('document5')->nullable();
$table->text('document5Details')->nullable();
$table->string('document6')->nullable();
$table->text('document6Details')->nullable();
$table->string('document7')->nullable();
$table->text('document7Details')->nullable();
//$table->string('docstatusvalue')->nullable();
$table->string('docstatusvalue')->default('Incomplete'); // Adjust as per your requirements
$table->timestamps();
});
}
你能帮我解决这个错误吗,错误信息显示
错误异常
未定义变量 $selectedCount (查看:D:\Projects\Live Projects\Hiring Portal (Laravel)\resources\views\dashboard.blade.php)
我正在尝试测试我的@Component@Component class Bean1(private val someRepository:RepositoryOne,private val someService:ServiceTwo,@Value(\'app.env\') private val envValue:Long 我的测试
我正在尝试测试我的@Component
@Component
class Bean1(
private val someRepository:RepositoryOne,
private val someService:ServiceTwo,
@Value("app.env") private val envValue:Long
我的测试看起来像
@ExtendWith(MockKExtension::class)
class Test(){
@MockK
lateinit var someRepository: RepositoryOne
@MockK
lateinit var someService: ServiceTwo
@InjectMockKs
lateinit var instanse: Bean1
fun Test1(){
TODO()
}
}
我如何 envValue
在 MockkedBean 中添加一些值。如果我使用这个,我会得到错误: kotlin.Long = <not able to lookup>)