Php 如何使用InfyOm Laravel生成器读取Laravel中的新函数?
我用InfyOm Laravel Generator制作了一个控制器、模型、视图等 我运行:Php 如何使用InfyOm Laravel生成器读取Laravel中的新函数?,php,laravel,generator,laravel-5.3,Php,Laravel,Generator,Laravel 5.3,我用InfyOm Laravel Generator制作了一个控制器、模型、视图等 我运行:php artisan infyom:scaffold Hotel 我从以下地方得到这个命令: 它生成控制器、模型、视图等 酒店的控制器如下所示: <?php namespace App\Http\Controllers; use App\Http\Requests\CreatehotelRequest; use App\Http\Requests\UpdatehotelRequest; use
php artisan infyom:scaffold Hotel
我从以下地方得到这个命令:
它生成控制器、模型、视图等
酒店的控制器如下所示:
<?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'));
}
}
看看laravel路由
你必须在你的路线上登记
示例(这应该应用于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.';
}
这可以帮助您查找/识别错误
希望有帮助 我必须在我的路线上登记。但是,这对我不起作用,答案是正确的。Infyom提供scaffold/api控制器并添加资源路由。如果你给它们添加了任何新功能,你必须提供路由;不要放弃,我最近也遇到了一些路线问题。稍微扩展一下语法:Route::get('adminlte-generator/public/hotels',['as'=>'public-hotels','uses'=>'hotelController@test']) . 使用“公共酒店”获取路线。@cssBlaster21895,您确定它有效吗?你试过了?我已经试过了,但它不起作用当什么都不起作用时,我只是运行了php artisan Optimization和composer dump autoload,但可以肯定的是,现在您只有路由问题了