phplaravellaravel-artisanlaravel-components

Laravel component class ignore due to component create in different folder


<?php

namespace App\View\Components;

use Illuminate\View\Component;

class Admin.-newclubform extends Component

{
    /**
     * Create a new component instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the view / contents that represent the component.
     *
     * @return \Illuminate\Contracts\View\View|\Closure|string
     */
    public function render()
    {echo "demo";
        return view('components.admin.-newclubform');
    }
}

enter image description here

I use php artisan make:component Admin.Newclubform command to create component in Admin Folder. views section working but class is ignored.

php artisan make:component Admin.Newclubform creates all class and view . class is generated by artisan command enter image description here


Solution

  • As mentioned by @shaedrich Admin.Newclubform is not a valid class name.

    So creating subfolder run command like below

    php artisan make:component Admin/NewClubForm
    

    This will create file inside

    App\View\Components\Admin\NewClubForm
    

    So your component look like this

    <?php
    
    namespace App\View\Components\Admin;
    
    use Illuminate\View\Component;
    
    class NewClubForm extends Component
    {
        /**
         * Create a new component instance.
         *
         * @return void
         */
        public function __construct()
        {
            //
        }
    
        /**
         * Get the view / contents that represent the component.
         *
         * @return \Illuminate\Contracts\View\View|\Closure|string
         */
        public function render()
        {
            return view('components.admin.new-club-form');
        }
    }
    

    then you can access like this

    <x-admin.newclubform></x-admin.newclubform>