DEV Community

El Morjani Mohamed
El Morjani Mohamed

Posted on • Edited on

Laravel Tip๐Ÿ’ก: Extract Validated Input Elegantly

We often redirect our users to specific routes using the "redirect()" method. Did you know there is a shorter and more expressive method called "to_route"? ๐Ÿš€

<?php

// ๐Ÿš€ Instead of this
return redirect()->route('profile');

// โœจ You can do this
return to_route('profile');
?>
Enter fullscreen mode Exit fullscreen mode

Both snippets achieve the same result, but to_route makes your code cleaner and more readable. Small changes can have a big impact! ๐Ÿ˜Š

Top comments (0)