8wDlpd.png
8wDFp9.png
8wDEOx.png
8wDMfH.png
8wDKte.png

laravel 中 $selectedCount 未定义

joseville 3月前

31 0

我正在尝试在 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)

帖子版权声明 1、本帖标题:laravel 中 $selectedCount 未定义
    本站网址:http://xjnalaquan.com/
2、本网站的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
3、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
4、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
5、站长邮箱:yeweds@126.com 除非注明,本帖由joseville在本站《laravel》版块原创发布, 转载请注明出处!
最新回复 (0)
  • 我正在尝试测试我的@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>)

返回
作者最近主题: