Issue
I'm working on tamil siddha project, but im stuck, because i don't know how to use tamil character as a slug.
routes.web
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', 'user\HomeController@index')->name('index');
Route::get('/home', 'HomeController@index')->name('home');
Route::resource('/questions', 'User\PostController', ['except' => ['show']]);
Route::get('/questions/{slug}', 'User\PostController@show')->name('post');
Route::resource('/tags', 'User\TagController');
How i created my slug:
combined my title and post_id, But while i'm using tamil character as a title, i could not combine it.
post controller
public function store(Request $request)
{
$this->validate($request,[
'title' => 'required',
'body' => 'required',
]);
$post = new Post;
$post -> title = $request -> title;
$post -> body = $request -> body;
$post -> tags = implode(', ', $request -> tags);
$post -> posted_by = 1;
$post -> save();
$post_ID = $post->post_id;
$post -> slug = $post_ID.'-'.str_slug($post -> title, '-');
$post -> save();
return redirect(route('questions.index'));
}
how do i resolve this problem?
Solution
Note that str_slug
is deprecated in Laravel 6 & 7, you can use Str::slug
instead
https://laravel.com/docs/7.x/helpers#method-str-slug
Regarding your issue, you can follow the instructions here that could help you: (consists of creating your own function extending the Laravel slug helper) http://killerwhalesoft.com/blog/make-laravel-slug-support-utf8-characters/
It's too long to copy here, therefore, I just put the link.
Answered By - Christophe Hubert Answer Checked By - Katrina (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.