如何使用InfyOm Laravel Generator读取Laravel中的新功能?

时间:2016-12-03 09:15:05

标签: php laravel generator laravel-5.3

我使用InfyOm Laravel Generator制作了控制器,模型,视图等。

我跑:php artisan infyom:scaffold Hotel

我从http://labs.infyom.com/laravelgenerator/docs/5.3/getting-started#generator-commands

获得了这个命令

它生成控制器,模型,视图等

控制器酒店是这样的:

<?php

namespace App\Http\Controllers;

use App\Http\Requests\CreatehotelRequest;
use App\Http\Requests\UpdatehotelRequest;
use App\Repositories\hotelRepository;
use App\Http\Controllers\AppBaseController;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

class hotelController extends AppBaseController
{
    /** @var  hotelRepository */
    private $hotelRepository;

    public function __construct(hotelRepository $hotelRepo)
    {
        $this->hotelRepository = $hotelRepo;
    }

    /**
     * Display a listing of the hotel.
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->hotelRepository->pushCriteria(new RequestCriteria($request));
        $hotels = $this->hotelRepository->all();

        return view('hotels.index')
            ->with('hotels', $hotels);
    }

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

    public function test()
    {
        die('test view');
    }

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

        $hotel = $this->hotelRepository->create($input);

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

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

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

        if (empty($hotel)) {
            Flash::error('Hotel not found');

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

        return view('hotels.show')->with('hotel', $hotel);
    }

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

        if (empty($hotel)) {
            Flash::error('Hotel not found');

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

        return view('hotels.edit')->with('hotel', $hotel);
    }

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

        if (empty($hotel)) {
            Flash::error('Hotel not found');

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

        $hotel = $this->hotelRepository->update($request->all(), $id);

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

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

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

        if (empty($hotel)) {
            Flash::error('Hotel not found');

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

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

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

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

我这样调用网址:http://localhost/adminlte-generator/public/hotels/create,结果是:酒店视图

我添加了新功能,该功能是Test。然后我调用这样的URL:http://localhost/adminlte-generator/public/hotels/test。它没有显示测试视图。

有什么解决方案可以解决我的问题吗?

1 个答案:

答案 0 :(得分:1)

看看laravel路由

https://laravel.com/docs/5.3/routing

您必须在路线上注册

示例(这应该适用于您的route / web.php)

Route::get('adminlte-generator/public/hotels', ['uses' => 'hotelController@test']);

我怀疑/create是如何运作的。也许他们在你运行artisan命令时为你提供了route :: resource。我不确定。 :)

修改

首先尝试一下:

Route::get('adminlte-generator/public/hotels', function() {
    echo 'Working.';
});

访问路线,如果你看到工作。问题出在您的控制器上。

尝试在您的路线上添加此内容:

public function test() {
    echo 'Working in controller.';
}

这可以帮助您找到/识别错误。

希望它有所帮助!