Well you can do that with using route parameters.
But you still have pagination as query string:
somesite.com/whatever/something?page=2
SEO has nothing to do with query string, what you refer to is just "friendly" url.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
My URL is currently like this -> http://localhost:8000/news?tags=1. 1 is ofcourse the ID of the tags in the database
i have tags with names (Entertainment, News) How can i make my URL Look like this lhttp://localhost:8000/entertainment instead of http://localhost:8000/news?tags=1
NewsController.php
<?php
namespace App\Http\Controllers;
use App\News;
use App\Tag;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class NewsController extends Controller
{
function __construct()
{
$this->middleware('auth', ['except' => ['index', 'show']]);
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
if($request->has('tags')){
$tag=Tag::find($request->tags);
$news=$tag->news;
}else{
$news= News::paginate(15);
}
return view('categories.news',compact('news'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('news.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//validate
$this->validate($request,[
'subject'=>'required|min:10',
'tags' => 'required',
'body' => 'required|min:20'
]);
//store
$news=auth()->user()->news()->create($request->all());
$news->tags()->attach($request->tags);
//redirect
return redirect()->route('news.index');
}
/**
* Display the specified resource.
*
* @param \App\News $news
* @return \Illuminate\Http\Response
*/
public function show(News $news)
{
return view('news.single', compact('news'));
}
/**
* Show the form for editing the specified resource.
*
* @param \App\News $news
* @return \Illuminate\Http\Response
*/
public function edit(News $news)
{
return view('news.edit', compact('news'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\News $news
* @return \Illuminate\Http\Response
*/
public function update(Request $request, News $news)
{
if(auth()->user()->id !== $news->user_id){
abort(401, "Please Login");
}
$this->validate($request,[
'subject'=>'required|min:10',
'body' => 'required|min:20'
]);
$news->update($request->all());
return redirect()->route('news.show', $news->slug)->withMessage('News Updated');
}
/**
* Remove the specified resource from storage.
*
* @param \App\News $news
* @return \Illuminate\Http\Response
*/
public function destroy(News $news)
{
if(auth()->user()->id !== $news->user_id){
abort(401, "Please Login");
}
$news->delete();
$news= News::paginate(15);
return view('categories.news', compact('news'));
}
}
Present URL
<a href="{{route('news.index', ['tags'=>$tag->id])}}">{{$tag->name}}</a>
ROUTES
Route::resource('/news', 'NewsController');
Route::get('/post/{news}', 'NewsController@show')->name('news.show');
ok, so its not possible to share the same url
You could leave /news/ as a resource controller and come up with a new route for your index, for instance
Route::get('news/tagged/{tag?}', 'NewsController@index')->name('news.index');
put this route before your resource route
Please or to participate in this conversation.