Laravel中的动态url路由

Laravel中的动态url路由,laravel,laravel-5,Laravel,Laravel 5,我是使用5.8版的Laravel新手 我不想为每个控制器手动设置路由 我想要的是,如果我给出任何url,例如- www.example.com/product/product/add/1/2/3 www.example.com/customer/customer/edit/1/2 www.example.com/category/category/view/1 对于上面的示例url,我希望该url应被视为 www.example.com/directoryname/controllerna

我是使用5.8版的Laravel新手

我不想为每个控制器手动设置路由

我想要的是,如果我给出任何url,例如-

www.example.com/product/product/add/1/2/3

www.example.com/customer/customer/edit/1/2

www.example.com/category/category/view/1
对于上面的示例url,我希望该url应被视为

www.example.com/directoryname/controllername/methodname/can have any number of parameter
我在我的项目中有很多控制器,所以我希望这个模式应该通过路由自动识别,我不需要一次又一次地手动指定目录名、控制器、方法和路由中的参数(参数)数量

试试这个:

Route::get('/product/edit/{id}',[
    'uses' => 'productController@edit',
    'as'=>'product.edit'
]);
Route::get('/products',[
    'uses' => 'productController@index',
    'as'=>'products'
]);
在控制器中:

 public function edit($id)
{
    $product=Product::find($id);

    return view('edit')->with('product',$product);
}
public function index()
{
    $products=Product::all();
    return view('index')->with('products',$products);
}
在索引视图中

@foreach($products as $product)
    <a href="{{ route('product.edit',['id'=>$product->id]) }}">Edit</a>
@endforeach
@foreach($products作为$product)
@endforeach
在编辑视图中

<p>$product->name</p>
<p>$product->price</p>
$product->name

$product->price


我想你错过了资源控制器和他的路由声明:嘿,先读路由