mstdmstdd Posted November 28, 2017 Share Posted November 28, 2017 Hello, In laravel 5.5 I want to make work out for my string values when submitting the form. For this I created Middleware app/Http/Middleware/WorkTextString.php : <?php namespace App\Http\Middleware; use Closure; use App\Http\Traits\funcsTrait; use function PHPSTORM_META\type; class WorkTextString { use funcsTrait; public function handle($request, Closure $next) { $request->name = $this->workTextString($request->name); // Fields I want to modify $request->description = $this->workTextString($request->description); return $next($request); } protected function workTextString($str) // my workout for any string { and in app/Http/Kernel.php I added my Middleware : protected $routeMiddleware = [ 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'WorkTextString'=>\App\Http\Middleware\WorkTextString::class, ]; In routes/api.php : Route::group([ 'prefix' => '/v1', 'namespace' => 'Api\V1', 'as' => 'api.'], function () { Route::resource('user_task_types', 'UserTaskTypesController', ['except' => ['create', 'edit']])->middleware('WorkTextString'); as I see my Middleware is triggered, but modifications are not saved to db. Which is the right way ? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/305782-in-laravel-55-middleware-modifications-are-not-saved-to-db/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.