I searched for answer and didn’t find any that will works for me.
I have table ‘articles’ where I store articles with ‘slug’ column.
In my route files I have route:
Route::get(‘article/{slug}’, ‘ArticleController@viewArticle’);
that works fine when I type for example /article/some-article-title and article will show, but I want to access from /some-article-title . I’v tried to change route like:
Route::get(‘{slug}’, ‘ArticleController@viewArticle’);
And that works when i put this at the end of file, but after all for example WYSIWYG now works (uploading files), and some images stopts work (404 error). I’v tried modyfing .htaccess file and still not working.
Any ideas?
I want to create anchor like this
<a href="http://www.domain.com/some-title-for-article">some-title-for-article</a>
but now the link looks like this:
<a href="http://www.domain.com/articles/some-title-for-article">some-title-for-article</a>
Routes file 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');
2
Answers
Please could you try to append a name to your route a call it with route name?
Like this:
Route::get('{slug}', 'ArticleController@viewArticle')->name('view.article');
and in your Blade file create the anchor with:
<a href="route('view.article')"
Since you’re not using route names, just use
url()
helper: