mardi 21 avril 2020

How to use tamil characters as a slug in laravel route?

I'm working on tamil siddha project, but im stuck, because i don't know how to use tamil character as a slug.

Code:

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 were created my slug:

combine my title and post_id. but, while im using tamil character as a title, i could not combine it.

code:(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'));
    }

Please any one help, how to resolve this proble. Thanks for advance..



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire