mercredi 18 août 2021

How To Hide ID from url ?? Laravel

I want to hide id from URL

http://example.com/photo/1234/image-name

I want it to change like this

http://example.com/photo/image-name

Is that there any way to remove or replace id from url.

CONTROLLER:

public function show($id, $slug = null)
{
    $response = Images::findOrFail($id);

if (Auth::check() && $response->user_id != Auth::user()->id && $response->status == 'pending' && Auth::user()->role != 'admin') {
    abort(404);
} else if (Auth::guest() && $response->status == 'pending') {
    abort(404);
}

$uri = $this->request->path();

if (str_slug( $response->title) == '') {

        $slugUrl  = '';
    } else {
        $slugUrl  = '/'.str_slug( $response->title );
    }

    $url_image = 'photo/'.$response->id.$slugUrl;

Href

<a href=""/>

Route

Route::get('photo/{id}/{slug?}','ImagesController@show');


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire