gpt4 book ai didi

Laravel URL 从 comain.com/category/slug 到 domain.com/category

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:35:57 26 4
gpt4 key购买 nike

我搜索了答案,但没有找到适合我的答案。我有一个表“articles”,我在其中存储带有“slug”列的文章。

在我的路线文件中我有路线:

Route::get('article/{slug}', 'ArticleController@viewArticle');

当我输入例如/article/some-article-title 并且文章会显示时效果很好,但我想从/some-article-title 访问。我试过像这样改变路线:

Route::get('{slug}', 'ArticleController@viewArticle');

当我把它放在文件末尾时,它就可以工作了,但毕竟,例如所见即所得现在可以工作(上传文件),并且一些图像停止工作(404 错误)。我已经尝试修改 .htaccess 文件,但仍然无法正常工作。

有什么想法吗?

我想创建这样的 anchor

<a href="http://www.domain.com/some-title-for-article">some-title-for-article</a> 

但现在链接看起来像这样:

<a href="http://www.domain.com/articles/some-title-for-article">some-title-for-article</a>

路由文件 web.php

Route::get('/', 'HomeController@index');

/* DEPLOY BITBUCKET */
Route::get('/deploy/', 'DeployController@index');
Route::post('/deploy/update',
['as' => 'deploy_update', 'uses' => 'DeployController@update']);

/* ADMIN PANEL */

Auth::routes();
Route::get('/admin/', 'AdminController@index');

/* ADMIN USERS */
Route::get('/admin/users', 'UserController@index');
Route::get('/admin/users/add/', 'UserController@add');
Route::post('/admin/users/create/', 'UserController@create');
Route::get('/admin/users/edit/{id}', 'UserController@edit');
Route::post('/admin/users/update/', 'UserController@update');
Route::delete('/admin/users/delete/{id}', 'UserController@delete');

/* ADMIN CATEGORIES */
Route::get('/admin/categories', 'CategoryController@index');
Route::get('/admin/categories/add/', 'CategoryController@add');
Route::post('/admin/categories/create/', 'CategoryController@create');
Route::get('/admin/categories/edit/{id}', 'CategoryController@edit');
Route::post('/admin/categories/update/', 'CategoryController@update');
Route::delete('/admin/categories/delete/{id}', 'CategoryController@delete');

/* ADMIN COMMENTS */
Route::get('/admin/comments', 'CommentController@index');
Route::get('/admin/comments/view/{id}', 'CommentController@view');
Route::get('/admin/comments/add/', 'CommentController@add');
Route::post('/admin/comments/create/', 'CommentController@create');
Route::post('/admin/comments/approve/{id}', 'CommentController@approve');
Route::delete('/admin/comments/delete/{id}', 'CommentController@delete');

/* ADMIN ARTICLES */
Route::get('/admin/articles', 'ArticleController@index');
Route::get('/admin/articles/view/{id}', 'ArticleController@view');
Route::get('/admin/articles/edit/{id}', 'ArticleController@edit');
Route::get('/admin/articles/add/', 'ArticleController@add');
Route::post('/admin/articles/create/', 'ArticleController@create');
Route::post('/admin/articles/approve/{id}', 'ArticleController@approve');
Route::delete('/admin/articles/delete/{id}', 'ArticleController@delete');
Route::post('/admin/articles/update/', 'ArticleController@update');

Route::post('image-upload','ImageController@imageUploadPost');

/* GALLERIES */

Route::get('/admin/galleries', 'GalleryController@index');
Route::get('/admin/galleries/view/{id}', 'GalleryController@view');
Route::get('/admin/galleries/edit/{id}', 'GalleryController@edit');
Route::get('/admin/galleries/add/', 'GalleryController@add');
Route::post('/admin/galleries/create/', 'GalleryController@create');
Route::post('/admin/galleries/approve/{id}', 'GalleryController@approve');
Route::delete('/admin/galleries/delete/{id}', 'GalleryController@delete');
Route::post('/admin/galleries/update/', 'GalleryController@update');

/* IMAGE CONTROLLER */
Route::delete('/admin/images/delete/{id}', 'ImageController@delete');
Route::get('/admin/images/info/{id}', 'ImageController@info');
Route::post('/admin/images/update/', 'ImageController@update');

/* CONTACT FORM */
Route::get('/kontakt/', 'ContactController@index');
Route::post('/kontakt/',
['as' => 'contact_send', 'uses' => 'ContactController@send']);

/* GALLERY UPLOAD */
Route::post('/gallery_upload/', 'GalleryController@upload');

/* ARTICLE CONTROLLER */
Route::get('{slug}', 'ArticleController@viewArticle')->name('view.article');
//Route::get('artykuly/{slug}', 'ArticleController@viewArticle');

最佳答案

请问您能否尝试为您的路线附加一个名称,并用路线名称来调用它?

像这样:

Route::get('{slug}', 'ArticleController@viewArticle')->name('view.article');

并在您的 Blade 文件中创建 anchor :

<a href="route('view.article')"

关于Laravel URL 从 comain.com/category/slug 到 domain.com/category,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41804734/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com