0
我創建了一個ProductController的資源在route.php文件是這樣的: -Laravel 5.0 |更改默認行爲的名字是不工作的資源控制器
Route::resource('products','ProductController',['names' => ['create' => 'products.add']]);
這裏是我的productController.php文件看起來像: -
<?php namespace lvtest\Http\Controllers;
use lvtest\Http\Requests;
use lvtest\Product;
use lvtest\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ProductController extends Controller {
/**
* Class constructor .. requires authentication
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$products = Product::all();
return view('products.productsList', ['products' => $products]);
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function add()
{
return 'Add a product';
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
return 'store new product?';
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id = null)
{
// $products = Product::all();
// print_r($products);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
return 'store new product?';
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
}
,並通過了「名」陣列,以改變的默認名稱創建方法添加。 當我到localhost:8000/products/add時,我得到一個空白頁。 如何解決這個
感謝您的回覆。 我知道這種方法,但我想知道是否有一種方法可以使用靜態方法**資源**。 +1 – 2015-03-25 12:13:43
它也適用於我使用Route ::獲取路線::資源的頂部? – 2015-11-23 08:46:15
但在PHP工匠路線中也提到了創建路由:列表 – 2015-11-23 08:47:05