Reputation: 7076
I've made a controller, model, view etc using InfyOm Laravel Generator.
I run: php artisan infyom:scaffold Hotel
I got this command from: http://labs.infyom.com/laravelgenerator/docs/5.3/getting-started#generator-commands
It generates the controller, model, view etc
The controller Hotel like this :
<?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'));
}
}
I call the URL like this: http://localhost/adminlte-generator/public/hotels/create, and the result is : hotel view
I add new function, The function is Test. Then I call the URL like this: http://localhost/adminlte-generator/public/hotels/test. It's not displaying the test view.
Is there any solution to solve my problem?
Upvotes: 1
Views: 1525
Reputation: 5732
Take a look at laravel routing
https://laravel.com/docs/5.3/routing
You must register it on your route
example (this should be apply on your route/web.php)
Route::get('adminlte-generator/public/hotels', ['uses' => 'hotelController@test']);
I have suspicions of how /create
is working. Maybe they provided the route::resource for you when you run artisan command. I'm not sure about it. :)
Edit
Try first this:
Route::get('adminlte-generator/public/hotels', function() {
echo 'Working.';
});
Access the route and if you see working. The problem is on your controller.
The try to add this on your route:
public function test() {
echo 'Working in controller.';
}
This can help you to find/identify the error.
Hope it helps!
Upvotes: 1