LispyGUy's avatar

Laravel-FakeId help

Trying to setup Laravel Fakeid https://github.com/Propaganistas/Laravel-FakeId

Followed the instructions and I'm having difficulty with this part.

Usage (from the setup instructions)

First of all, make sure the model is bound to Laravel's Router using the model() method, e.g. on top of the routes.php file (or in the boot() method of RouteServiceProvider if you use route caching):

Route::model('mymodel', 'App\MyModel'); (end setup instructions)

My route

Route::get('Item/{Item_id}', 'ItemController@ItemInfo');

How would I set it for my route so it shows the item ids as fake and not the real id? Do I also need to add something to the view?

Thanks for any help

0 likes
1 reply
JohnBraun's avatar

I just checked out this package and I must admit the readme is a somewhat incomplete. I've submitted a PR adding a section on the usage in the views.

After you've followed the setup instructions, you can use the package as follows:

Given you have a route to show a specific items in your web.php:

Route::get('items/{item}', 'ItemController@show')->name('items.show');

To generate a URL to a certain item, you can use the following code in your view:

{{ route('items.show', Item::first()) }}

This generates a link to 'items/{hash}' where the "hash" is translated to the corresponding ID. This way, an item with an ID of 1 can have a link /items/579747662. In that way, users of your application do not get information on how many items there are and cannot guess the next / previous entries.

Please or to participate in this conversation.