ProiodaController.php第32行中的Laravel CRUD生成器FatalThrowableError:调用未定义的方法App \ DataTables \ ProiodaDataTable :: render()

时间:2017-04-01 17:17:12

标签: php mysql laravel

我正在开发一个Laravel 5.4项目并且我已经下载了crud generator包,但是当我使用--datatables=true标记并且我转到视图时,我收到错误:< / p>

FatalThrowableError in ProiodaController.php line 32:
Call to undefined method App\DataTables\ProiodaDataTable::render()

我正在使用yajra/laravel-datatables这样的生成器来工作需要它。

Generator已生成所有视图文件控制器请求模型存储库,并在名为DataTables的文件夹中生成名为ProiodaDataTable.php的文件。

以下是ProiodaController.php

<?php
    namespace App\Http\Controllers;
    use App\DataTables\ProiodaDataTable;
    use App\Http\Requests;
    use App\Http\Requests\CreateProiodaRequest;
    use App\Http\Requests\UpdateProiodaRequest;
    use App\Repositories\ProiodaRepository;
    use Flash;
    use App\Http\Controllers\AppBaseController;
    use Response;

class ProiodaController extends AppBaseController
{
    /** @var  ProiodaRepository */
    private $proiodaRepository;

    public function __construct(ProiodaRepository $proiodaRepo)
    {
        $this->proiodaRepository = $proiodaRepo;
    }

    /**
    * Display a listing of the Proioda.
    *
    * @param ProiodaDataTable $proiodaDataTable
    * @return Response
    */
    public function index(ProiodaDataTable $proiodaDataTable)
    {
        return $proiodaDataTable->render('proiodas.index');
    }

    /**
    * Show the form for creating a new Proioda.
    *
    * @return Response
    */
    public function create()
    {
        return view('proiodas.create');
    }

/**
 * Store a newly created Proioda in storage.
 *
 * @param CreateProiodaRequest $request
 *
 * @return Response
 */
public function store(CreateProiodaRequest $request)
{
    $input = $request->all();

    $proioda = $this->proiodaRepository->create($input);

    Flash::success('Proioda saved successfully.');

    return redirect(route('proiodas.index'));
}

/**
 * Display the specified Proioda.
 *
 * @param  int $id
 *
 * @return Response
 */
public function show($id)
{
    $proioda = $this->proiodaRepository->findWithoutFail($id);

    if (empty($proioda)) {
        Flash::error('Proioda not found');

        return redirect(route('proiodas.index'));
    }

    return view('proiodas.show')->with('proioda', $proioda);
}

/**
 * Show the form for editing the specified Proioda.
 *
 * @param  int $id
 *
 * @return Response
 */
public function edit($id)
{
    $proioda = $this->proiodaRepository->findWithoutFail($id);

    if (empty($proioda)) {
        Flash::error('Proioda not found');

        return redirect(route('proiodas.index'));
    }

    return view('proiodas.edit')->with('proioda', $proioda);
}

/**
 * Update the specified Proioda in storage.
 *
 * @param  int              $id
 * @param UpdateProiodaRequest $request
 *
 * @return Response
 */
public function update($id, UpdateProiodaRequest $request)
{
    $proioda = $this->proiodaRepository->findWithoutFail($id);

    if (empty($proioda)) {
        Flash::error('Proioda not found');

        return redirect(route('proiodas.index'));
    }

    $proioda = $this->proiodaRepository->update($request->all(), $id);

    Flash::success('Proioda updated successfully.');

    return redirect(route('proiodas.index'));
}

/**
 * Remove the specified Proioda from storage.
 *
 * @param  int $id
 *
 * @return Response
 */
public function destroy($id)
{
    $proioda = $this->proiodaRepository->findWithoutFail($id);

    if (empty($proioda)) {
        Flash::error('Proioda not found');

        return redirect(route('proiodas.index'));
    }

    $this->proiodaRepository->delete($id);

    Flash::success('Proioda deleted successfully.');

    return redirect(route('proiodas.index'));
}

}

这是ProiodaDataTable.php

    <?php

    namespace App\DataTables;

    use App\Models\Proioda;
    use Form;
    use Yajra\Datatables\Facades\Datatables;
    use Illuminate\Support\Facades\View;

    class ProiodaDataTable extends Datatables
    {

        /*
         * @return \Illuminate\Http\JsonResponse
         */
        public function ajax()
        {
            return $this->datatables
                ->eloquent($this->query())
                ->addColumn('action', 'proiodas.datatables_actions')
                ->make(true);
        }

        /**
         * Get the query object to be processed by datatables.
         *
         * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
         */
        public function query()
        {
            $proiodas = Proioda::query();

            return $this->applyScopes($proiodas);
        }

        /**
         * Optional method if you want to use html builder.
         *
         * @return \Yajra\Datatables\Html\Builder
         */
        public function html()
        {
            return $this->builder()
                ->columns($this->getColumns())
                ->addAction(['width' => '10%'])
                ->ajax('')
                ->parameters([
                    'dom' => 'Bfrtip',
                    'scrollX' => false,
                    'buttons' => [
                        'print',
                        'reset',
                        'reload',
                        [
                             'extend'  => 'collection',
                             'text'    => '<i class="fa fa-download"></i> Export',
                             'buttons' => [
                                 'csv',
                                 'excel',
                                 'pdf',
                             ],
                        ],
                        'colvis'
                    ]
                ]);
        }
    /**
     * Get columns.
     *
     * @return array
     */
    private function getColumns()
    {
        return [
            'onoma' => ['name' => 'onoma', 'data' => 'onoma'],
            'perigrafi' => ['name' => 'perigrafi', 'data' => 'perigrafi'],
            'timi' => ['name' => 'timi', 'data' => 'timi']
        ];
    }

    /**
     * Get filename for export.
     *
     * @return string
     */
    protected function filename()
    {
        return 'proiodas';
    }
}

0 个答案:

没有答案