Bagisto Forum

    Bagisto

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    I want create a faq for products module

    Modules
    2
    5
    426
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Mayankpanchal last edited by

      I have create a package for FAQ , I have followed the way of cms package. but i facing this issue.i have attched a screenshot of an error. i have create a contracts model file but i have face error.![alt text](error1..png image url) .

      I have create a following steps after model file create
      1)composer dump-autoload
      2)clear config cache
      3)clear route cache

      1 Reply Last reply Reply Quote 0
      • devansh-webkul
        devansh-webkul last edited by

        Hi @Mayankpanchal,

        Can you share a ProductFaq files? So that I can check because it look like either you have not updated your namespace or you have not registered a folder in composer dump-autoload for autoloading.

        1 Reply Last reply Reply Quote 0
        • M
          Mayankpanchal last edited by

          @devansh-webkul

          Here is admin faq controller file code

          <?php

          namespace Webkul\ProductFaq\Http\Controllers\Admin;

          use Illuminate\Routing\Controller;
          use Illuminate\Foundation\Bus\DispatchesJobs;
          use Illuminate\Foundation\Validation\ValidatesRequests;
          use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
          use Webkul\ProductFaq\Repositories\ProductFaqRepository;

          class ProductFaqController extends Controller
          {
          use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

          /**
           * Contains route related configuration
           *
           * @var array
           */
          protected $_config;
          
          /**
           * To hold the CMSRepository instance
           * 
           * @var \Webkul\ProductFaq\Repositories\ProductFaqRepository
           */
          protected $productFaqRepository;
          
          /**
           * Create a new controller instance.
           *
           * @return void
           */
          public function __construct(ProductFaqRepository $productFaqRepository)
          {
              $this->middleware('admin');        
          
              $this->productFaqRepository = $productFaqRepository;
          
              $this->_config = request('_config');
          }
          
          /**
           * Display a listing of the resource.
           *
           * @return \Illuminate\View\View
           */
          public function index()
          {
              return view($this->_config['view']);
          }
          
          /**
           * Show the form for creating a new resource.
           *
           * @return \Illuminate\View\View
           */
          public function create()
          {
              return view($this->_config['view']);
          }
          
          /**
           * Store a newly created resource in storage.
           *
           * @return \Illuminate\Http\Response
           */
          public function store()
          {
              $data = request()->all();
          
              $this->validate(request(), [
                  'faq_question' => 'required',
                  'faq_answer'   => 'required',
                  'status' => 'required',
                  'sort_order' => 'required'
              ]);
              
              /*$page = $this->productFaqRepository->create(request()->all());
          
              session()->flash('success', trans('admin::app.response.create-success', ['name' => 'page']));
          
              return redirect()->route($this->_config['redirect']);*/
          }
          
          /**
           * Show the form for editing the specified resource.
           *
           * @param  int  $id
           * @return \Illuminate\View\View
           */
          public function edit($id)
          {
              return view($this->_config['view']);
          }
          
          /**
           * Update the specified resource in storage.
           *
           * @param  int  $id
           * @return \Illuminate\Http\Response
           */
          public function update($id)
          {
              
          }
          
          /**
           * Remove the specified resource from storage.
           *
           * @param  int  $id
           * @return \Illuminate\Http\Response
           */
          public function destroy($id)
          {
              
          }
          

          }

          and repository code

          <?php

          namespace Webkul\ProductFaq\Repositories;

          use Webkul\Core\Eloquent\Repository;

          class ProductFaqRepository extends Repository
          {
          /**
          * Specify Model class name
          *
          * @return mixed
          */
          function model()
          {
          return 'Webkul/ProductFaq/Contracts/ProductFaq';
          }

          /**
           * @param  array  $data
           * @return \Webkul\ProductFaq\Contracts\ProductFaq
           */
          public function create(array $data)
          {
              $model = $this->getModel();
              $page = parent::create($data);
              return $page;
          }
          
          /**
           * @param  array  $data
           * @param  int  $id
           * @param  string  $attribute
           * @return \Webkul\CMS\Contracts\CmsPage
           */
          public function update(array $data, $id, $attribute = "id")
          {
              $page = $this->find($id);
              parent::update($data, $id, $attribute);
              return $page;
          }
          

          }

          Model file

          <?php

          namespace Webkul\ProductFaq\Contracts;

          interface ProductFaqModel
          {
          }

          1 Reply Last reply Reply Quote 0
          • devansh-webkul
            devansh-webkul last edited by

            Hi @Mayankpanchal,

            Did you register your created package in config/app.php and composer.json for autoload?

            1 Reply Last reply Reply Quote 0
            • M
              Mayankpanchal last edited by Mayankpanchal

              @devansh-webkul

              For now error was fixed . I was created a package using Bagisto package generator so it's create a repository file like this.
              <?php

              namespace Webkul\ProductFaq\Repositories;

              use Webkul\Core\Eloquent\Repository;

              class ProductFaqRepository extends Repository
              {
              /**
              * Specify Model class name
              *
              * @return mixed
              */
              function model()
              {
              return 'Webkul/ProductFaq/Contracts/ProductFaq';
              }
              }

              But solution is that we have to write backward slash for return model like this

              function model()
              {
              return 'Webkul\ProductFaq\Contracts\ProductFaq';
              }

              1 Reply Last reply Reply Quote 0
              • First post
                Last post