reference: https://medium.com/@kshitij206/creating-title-slugs-with-laravel-5bc59080cce6
: https://anooserve.com/posts/2/adding-url-slugs-laravel-blog
blade way:
link in href: @foreach($projects as $project)
web.php: Route::get('/projectdetail/{id}/{slug}', 'FrontController@projectdetail')->name('front.projectshow');
controller way :
$project=Project::find($id);
: https://anooserve.com/posts/2/adding-url-slugs-laravel-blog
blade way:
<script>
$("#title").keyup(function(){
var name = $(this).val();
var slug = name.toLowerCase();
slug = slug.replace(/[^a-zA-Z0-9]+/g,'-');
$("#slug").val(slug);
$(this).val(name);
});
</script>
<div class="form-group ">
<label for="title">Title</label>
<input class="form-control" type="text" name="title" id="title" value="{{old('title')}}">
</div>
<div class="form-group ">
<label for="slug">slug</label>
<input class="form-control" type="text" name="slug" id="slug" value="{{Request::old('slug')}}" readonly>
</div>
link in href: @foreach($projects as $project)
<a href="{{route('front.projectshow',[$project->id,$project->slug])}}">
web.php: Route::get('/projectdetail/{id}/{slug}', 'FrontController@projectdetail')->name('front.projectshow');
controller way :
public function projectdetail($id,$name)
{
$title=$project->title;
$slug = str_slug($title, '-');
Comments
Post a Comment