首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用InfyOm Laravel发生器读取Laravel中的新功能?

如何用InfyOm Laravel发生器读取Laravel中的新功能?
EN

Stack Overflow用户
提问于 2016-12-03 09:15:04
回答 1查看 1.4K关注 0票数 1

我已经做了一个控制器,模型,视图等使用InfyOm拉力发生器。

我跑:php artisan infyom:scaffold Hotel

我从:http://labs.infyom.com/laravelgenerator/docs/5.3/getting-started#generator-commands获得了以下命令

它生成控制器、模型、视图等。

这样的控制员酒店:

代码语言:javascript
复制
<?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'));
    }
}

我将URL调用为:http://localhost/adminlte-generator/public/hotels/create,其结果是:

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

有什么办法解决我的问题吗?

EN

回答 1

Stack Overflow用户

发布于 2016-12-03 09:34:58

看一看拉拉路线

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

你必须在你的路线上登记

示例(这应该适用于路由/web.php)

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

我怀疑/create是如何工作的。也许,当您运行artisan命令时,它们为您提供了路由::资源。我不太确定。:)

编辑

先试试这个:

代码语言:javascript
复制
Route::get('adminlte-generator/public/hotels', function() {
    echo 'Working.';
});

进入路线,如果你看到工作。问题在你的控制器上。

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

代码语言:javascript
复制
public function test() {
    echo 'Working in controller.';
}

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

希望能帮上忙!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40946133

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档