Jump to content
Sign in to follow this  
mstdmstdd

In laravel 5.5 middleware modifications are not saved to db

Recommended Posts

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!

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.