Laravel Community Tools by Tighten

Category "Requests and Input" tricks

68 tricks
I made a filter for Laravel 5.0 , you can redirect non-www URLs to www URL and you don't need to write any difficult htaccess codes . Just put the filter in routes.php and use it for any Routes you want them to be with WWW . This snipped code is made by www.larabook.ir
hpakdaman 10 years ago 16631
In Laravel 5, by default you have CSRF in every single POST. If you are new to Laravel and you use the usual HTML code to create inputs and forms then you will definitely encounter that error. Also, if you are coming from Laravel 4, again you might not know how to solve this error since 'Illuminate\Html\HtmlServiceProvider' is not installed by default anymore and HTML inputs and form have to be used. There are 3 solutions in order to fix it. 1) If you want to keep the usual HTML code and not use 'Illuminate\Html\HtmlServiceProvider' (since it is not installed by default in Laravel 5), then you can delete this line of code '\App\Http\Middleware\VerifyCsrfToken::class,' in app/Http/Kernel.php. However this is not a good practice. You can still do that though, in case you are building something small or an API. 2) You can install 'Illuminate\Html\HtmlServiceProvider' and do it the old good Laravel 4 way, which uses tokens by default, thus you don't have to worry about it anymore. 3) The last solution is in case you want to code the front end with the usual HTML code then you can use this line in your layout or in case you don't have a layout then in every single page. <input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" /> You can get Laravel 5 tutorials and projects for all levels (Beginners-Intermediate-Advanced) in this website www.codeexecutable.com/courses
codeexecut... 10 years ago 9783
Let's say, that your user provide inputs which has arrays like multiple accounts and different crediting and debiting amount, and you need to validate if they are balancing. You will need to extract the array and do some sort of manipulations before proceeding to validation...You can just overload the all() method in your form request class
kamaroly 10 years ago 12717
5.0
Session time out for logged in user (middleware way) for prevent dashboard or ... access after specify time. if we use this middleware in route groups, it will be run on every request under route group. with this code we do not need to change php.ini file or laravel session config file and default settings are appropriate. Do not forget to register middleware in app\Http\Kernel : 'timeout' => 'App\Http\Middleware\SessionTimeout', Other notices: 1- we can use middleware paramaters in laravel 5.1 for custom conditions. 2- we must redirect user back (after session timeout and log out ), to prevent user navigate to come back. 3- we must show a message to user (after session timeout and log out), that you logged out after [20] minutes that you were not active. Our Persian web app for time management is: https://timenix.com If you have a better idea please comment it. ♥
ivahidmont... 10 years ago 87543
Helper function to mass-map routes to methods. I use this setup in development to quickly map all "test/*" routes to a Test controller, to test out arbitrary PHP code. Updated version also supports DI in controller methods. Updated to correctly fill optional arguments.
davestewar... 10 years ago 12531
5.0
The example doesn't cover every single aspect, but the very major things.
Mahmoudz 10 years ago 16069
5.0
When user clicks on "delete" button, open a confirmation box before deleting an item.
ismaeltoe 10 years ago 46620
Auth::attempt($auth) giving problem. ErrorException in ClassLoader.php line 317: Uninitialized string offset: 0
Sanjar7 10 years ago 9853
5.0